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 39 40 41 42 43 44
|
const unsigned a [] = {300,4,6,1,5,600,2,800};
void sort ( unsigned a[], unsigned size)
{
unsigned compare;
unsigned answer;
unsigned k;
printf("[");
for (; 0 < size; size--)
{
printf(" %u,", a[size-1]);
for (compare = 1; compare <= size; compare++)
{
if (a[compare - 1] > a[compare])
{
answer = a[compare - 1];
a[compare - 1] = a [compare];
a[compare] = answer;
}
}
}
printf("]\n");
}
/*OUTPUT
[ 800, 600, 300, 6, 5, 4, 2, 1,]
*/
|