I prefer to use braces even when they are optional, so this is how I would style your function:
Code:
void sortArray(float nums[], int last)
{
int smallest;
int temp;
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++;
}
}
temp = nums[current];
nums[current] = nums[smallest];
nums[smallest] = temp;
}
}
Now, observe this line:
Code:
for (int walk = current + 1; walk <= current; walk++)
walk is set to current + 1, hence walk > current, thus walk <= current is always false, so the inner loop's body is never entered. Therefore, we can simplify your code to:
Code:
void sortArray(float nums[], int last)
{
int smallest;
int temp;
for (int current = 0; current < last; current++)
{
smallest = current;
temp = nums[current];
nums[current] = nums[smallest];
nums[smallest] = temp;
}
}
Since smallest == current, the swap is a self-swap, which has no net effect. The loop does no other work, and the function has no other code. Therefore, we can simplify your function to:
Code:
void sortArray(float nums[], int last) {}
Is this really the code that you compiled and tested?