Help with bubble sort
I'm having sorting out the numbers from lowest to highest. Can you guys help me? Here it what I have so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
unsigned a [] = {300,4,6,1,5,600,1,800};
void sort ( unsigned a[], unsigned size)
{
unsigned count;
unsigned compare;
unsigned answer;
for (count = 0; count < size; count--)
{
for (compare = 1; compare < size; compare++)
{
if (a[compare - 1] > a[compare])
{
answer = a[compare - 1];
a[compare - 1] = a [compare];
a[compare] = answer;
}
}
}
}
|
Topic archived. No new replies allowed.