diff --git a/src/functional/qsort.c b/src/functional/qsort.c index b45c080..5927340 100644 --- a/src/functional/qsort.c +++ b/src/functional/qsort.c @@ -13,8 +13,13 @@ static int icmp(const void *a, const void *b) return *(int*)a - *(int*)b; } +static int ccmp(const void *a, const void *b) +{ + return *(char*)a - *(char*)b; +} + /* 26 items -- even */ -static char *s[] = { +static const char *s[] = { "Bob", "Alice", "John", "Ceres", "Helga", "Drepper", "Emeralda", "Zoran", "Momo", "Frank", "Pema", "Xavier", @@ -23,35 +28,103 @@ static char *s[] = { "Lulu", "Quincy", "Osama", "Riley", "Ursula", "Sam" }; +static const char *s_sorted[] = { + "Alice", "Bob", "Ceres", "Drepper", + "Emeralda", "Frank", "Gedun", "Helga", + "Irina", "John", "Karnica", "Lulu", + "Momo", "Nono", "Osama", "Pema", + "Quincy", "Riley", "Sam", "Tsering", + "Ursula", "Vincent", "Wiener", "Xavier", + "Yeva", "Zoran" +}; + /* 23 items -- odd, prime */ static int n[] = { 879045, 394, 99405644, 33434, 232323, 4334, 5454, 343, 45545, 454, 324, 22, 34344, 233, 45345, 343, 848405, 3434, 3434344, 3535, 93994, 2230404, 4334 }; +static int n_sorted[] = { + 22, 233, 324, 343, 343, 394, 454, 3434, + 3535, 4334, 4334, 5454, 33434, 34344, 45345, 45545, + 93994, 232323, 848405, 879045, 2230404, 3434344, 99405644 +}; -int main(void) +static void string_sort(const char **a, const char **a_sorted, int len) { int i; - - qsort(s, sizeof(s)/sizeof(char *), sizeof(char *), scmp); - for (i=0; i 0) { + qsort(a, len, sizeof *a, scmp); + for (i=0; i n[i+1]) { +static void integer_sort(int *a, int *a_sorted, int len) +{ + int i; + qsort(a, len, sizeof *a, icmp); + for (i=0; i