Hi everyone,
I am writing a function that needs to sort the rows of a 2D matrix in ascending order.
To so, I first wrote the function to treat a 1D array and, by analogy, tried to build one that takes an array of pointers as argument, but I am not sure where I am doing that wrong, since I am not getting the sorted array in return.
I post my code below, I hope someone can help
All the best
cfd
In the following code, *array[] that is passed is a 2D matrix of "lenght" rows and 6 columns:
Code:
void sortAscend(float *array[], int length)
{
int i, j, temp, test;
for(i = length - 1; i > 0; i--)
{
test=0;
for(j = 0; j < i; j++)
{
if(*array[1] > *(array[1]+1)) /* compare neighboring elements */
{
temp = *array[1]; /* swap array[j] and array[j+1] */
*array[1] = *(array[1]+1);
*(array[1]+1) = temp;
test=1;
}
} /*end for j*/
if(test==0) break; /*will exit if the list is sorted!*/
} /*end for i*/
}