I have to write a function to sort a list of numbers into ascending and descending order. I've figured out how to do it in ascending order. So i thought that to do descending order, I would just have to switch the sign from greater than, to less than but it doesn't work. After the first element it stops.

Code:void sort(float b[], int size, int direction) { float tmp; int k,lt; lt= size-1; if(direction == 1){ //ascending for (k = 0; k < size; k++){ if(b[k]>b[lt]){ tmp = b[i]; b[k] = b[lt]; b[lt] = tmp; } } } if(direction == 2){ //descending for (k = 0; k < size; k++){ if(b[k]<b[lt]){ tmp = b[k]; b[k] = b[lt]; b[lt] = tmp; } } } }