diff options
author | Jakob Kaivo <jkk@ung.org> | 2020-08-16 12:15:30 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2020-08-16 12:15:30 -0400 |
commit | 75f2a7c3d2bed3c1c5add63325c8052ab6749afe (patch) | |
tree | 5333dc83ba6e59cfc539c345227d558ce5defe7c /src/stdlib/_qsort.h | |
parent | 8d4af013972f64dbabb7176706c18a94a63792f2 (diff) |
merge _qsort.h directly into qsort.c
Diffstat (limited to 'src/stdlib/_qsort.h')
-rw-r--r-- | src/stdlib/_qsort.h | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/src/stdlib/_qsort.h b/src/stdlib/_qsort.h deleted file mode 100644 index 475932a7..00000000 --- a/src/stdlib/_qsort.h +++ /dev/null @@ -1,33 +0,0 @@ -#include <stdlib.h> - -static void __swap(char *base, size_t size, size_t b, size_t c) -{ - char *x = base + (size * b); - char *y = base + (size * c); - size_t i; - - for (i = 0; i < size; i++) { - char tmp = x[i]; - x[i] = y[i]; - y[i] = tmp; - } -} - -static void __qsort(char *base, size_t size, size_t lo, size_t hi, int (*compar)(const void *, const void *)) -{ - size_t i = lo, j = 0; - if (lo >= hi) { - return; - } - - for (j = lo; j < hi; j++) { - if (compar(base + (size * j), base + (size * hi)) < 0) { - __swap(base, size, i, j); - i++; - } - } - __swap(base, size, i, hi); - - __qsort(base, size, lo, i - 1, compar); - __qsort(base, size, i + 1, hi, compar); -} |