Insertion sort
Hello everyone! I am begginer in this, and really need some help. It is simple programm, but i have a problem with line 39 how can i pass that number back to main? Thank you very much!!!!!
(I need numcount to count how many times data needed to be moved in order to sort 10 integers)
Code:
int main()
{
int array[10];
int last=9;
int i;
int numcount;
int num;
for (i=0;i < 10;i++)
array[i] = rand() % 10;
insertionSort(array, last , numcount);
int t;
printf(" Integers have been sorted:");
for ( t=0; t < 10; t++)
printf(" %d ,", array[t]);
printf(" \nNumber of moves needed to sort array is: %d", numcount);
system("PAUSE");
return 0;
}
int insertionSort ( int list[], int last, int numcount ){
int hold;
int counting=0;
int walker;
int current;
for ( current = 1; current <= last; current++){
hold = list[current];
counting++;
for (walker = current - 1; walker >= 0 && hold < list[walker]; walker--){
list[walker+1] = list[walker];
counting++;
}
list [walker + 1] = hold;
}
numcount= counting;
//(line 39)
return numcount;
}