I'm attempting to write a function to sort a series of values into asscending order:
Code:
void sort(float numbers[]) /* function to sort array */
{
i = 0;
while( i < (size) )
{
j = i + 1;
while( j <= size )
{
if( A[i] > A[j] )
{
temp = A[i];
A[i] = A[j];
A[j] = temp;
}
j++;
}
i++;
}
for (i = 0; i < size; i++)
printf("\nThe sorted x-values are: (%f)", A[i]); /* displays (x,y) cooridinates */
printf("\n");
}
Now, it compiles and runs fine but it seems to set the largest value in the array to zero and then re-order the values as it should. Any idea why it's doing that?
Many thanks,
Chris