I can't seem to get this sorting alogorithm to work:
#include <iostream>
void sortAssending(int nums[], int size);
int main()
{
int nums[] = {175,167,160,164,183,187,188,179,176,175,
169,175,176,178,165,160,173,165,187,178};
sortAssending(nums, 20);
for (int i=0; i<20; i++)
{
std::cout << nums[i] << std::endl;
}
system("PAUSE");
}
void sortAssending(int nums[], int size)
{
for (int start=0; start<size; start++)
{
for (int end=size-1; end>=0; end--)
{
if (nums[start] > nums[end])
{
int temp = nums[start];
nums[start] = nums[end];
nums[end] = temp;
}
}
}
}
It seems to do everything right except the very last number is not in place. Can anyone spot the problem?