diff options
-rw-r--r-- | grailsort.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/grailsort.c b/grailsort.c index ac0bf20..a585b2b 100644 --- a/grailsort.c +++ b/grailsort.c @@ -20,10 +20,9 @@ void merge(char *buf, char *base, size_t anmel, size_t bnmel, size_t width, cmpf char *a = buf; char *b = base + anmel * width; - while (anmel && cmp(base, b) <= 0) { - anmel -= 1; - base += width; - } + size_t skip = binary_search(b, base, anmel, width, cmp); + anmel -= skip; + base += skip * width; swap(base, a, anmel * width); |