diff --git a/samples/qsort.c b/samples/qsort.c index 98e210c..cabf020 100644 --- a/samples/qsort.c +++ b/samples/qsort.c @@ -6,13 +6,22 @@ int cmp(const void *p, const void *q) return *(int*)p - *(int*)q; } -main() +#define N 20 +int a[N]; + +int main(void) { - int values[] = { 49, 2, 180, 23, 77, 13, 29, 88 }; - int n, i; + int i; - n = sizeof(values)/sizeof(int); - qsort(values, n, sizeof(int), cmp); - for (i = 0; i < n; i++) - printf("values[%d] = %d\n", i, values[i]); + printf("Before:"); + for (i = 0; i < N; i++) { + a[i] = rand() / (RAND_MAX / 100 + 1); + printf(" %2d", a[i]); + } + printf("\n"); + qsort(a, sizeof(a)/sizeof(a[0]), sizeof(a[0]), cmp); + printf("After: "); + for (i = 0; i < N; i++) printf(" %2d", a[i]); + printf("\n"); + return 0; }