Skip to content

Commit

Permalink
issue #17: updated sample for qsort.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kray-G committed Nov 11, 2019
1 parent d062256 commit bf0fe55
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions samples/qsort.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit bf0fe55

Please sign in to comment.