Skip to content
Snippets Groups Projects
Verified Commit 3023dbb3 authored by Jeremy Soller's avatar Jeremy Soller
Browse files

Add qsort test

parent 7195c9a6
No related branches found
No related tags found
No related merge requests found
...@@ -53,6 +53,7 @@ EXPECT_NAMES=\ ...@@ -53,6 +53,7 @@ EXPECT_NAMES=\
stdlib/div \ stdlib/div \
stdlib/env \ stdlib/env \
stdlib/mkostemps \ stdlib/mkostemps \
stdlib/qsort \
stdlib/rand \ stdlib/rand \
stdlib/rand48 \ stdlib/rand48 \
stdlib/random \ stdlib/random \
......
Before: 23 16 8 4 42 15
After: 4 8 15 16 23 42
#include <stdio.h>
#include <stdlib.h>
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
int values[] = { 23, 16, 8, 4, 42, 15 };
int cmpfunc (const void * a_ptr, const void * b_ptr) {
int a = *(const int *)a_ptr;
int b = *(const int *)b_ptr;
return a - b;
}
int main () {
int i;
printf("Before: ");
for(i = 0; i < ARRAY_SIZE(values); i++) {
printf("%d ", values[i]);
}
printf("\n");
qsort(values, ARRAY_SIZE(values), sizeof(int), cmpfunc);
printf("After: ");
for(i = 0; i < ARRAY_SIZE(values); i++) {
printf("%d ", values[i]);
}
printf("\n");
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment