Having trouble sorting an Array that has a zero in it.
Hey guys, I was just wondering if someone could take a look at my code real quick. I'm sorting an array, and when it comes to a zero it obviously prints zero's from that point on. I'm using a simple selection sort, and it works fine as long as there are no zero's in the array. Could suggest a fix to this problem???
I want it to just print the 0 and resume sorting, but I've been looking at it for hours and can't seem to think of something to make that happen.
void sortArray (float nums, int last)
for (int current = 0; current < last; current++)
smallest = current;
for (int walk = current + 1; walk <= current; walk++)
if (nums[walk] < nums[smallest] && nums[smallest] != 0)
smallest = walk;
else if (nums[smallest] == 0)
smallest = walk++; //Here's where I think my problem is...
temp = nums[current];
nums[current] = nums[smallest];
nums[smallest] = temp;
Thanks so much for any help...