#include <stdio.h>
#include <stdlib.h>
static int compare (void const *pa, void const *pb)
{
int const *pi_a = pa;
int const *pi_b = pb;
if (*pi_a == *pi_b)
{
return 0;
}
else
{
if (*pi_a > *pi_b)
{
return 1;
}
else
{
return -1;
}
}
}
static void print (int *p, size_t n)
{
size_t i;
for (i = 0; i < n; i++)
{
printf ("%d ", p[i]);
}
printf ("\n" );
}
int main (void)
{
int a[] = {2, 4, 7, 6, 1, 5, 8, 4};
qsort (a, sizeof a / sizeof *a, sizeof *a, compare);
print (a, sizeof a / sizeof *a);
(getchar)();
return 0;
}
|