You SortArray function logic is wrong. You are finding maxindex
from i
to last index
and replacing it with last index
and then increment i
. In first iteration the largest number reaches end thereafter in subsequent iterations, the last index
only will be selected as maxindex
and no change in array will be there.
Instead you always need to iterate from first index and upto one index less than previous last index.
void sortArray (int numbers[]) /*Function sortArray*/
{
int i , maxInd;
for (i=size-1; i>=0;i--)
{
maxInd = indexMax (numbers, 0, i);
swap (numbers, i, maxInd);
}
}