From f9a298c1b802c6e4b298ae59836ab50f8ce29558 Mon Sep 17 00:00:00 2001 From: q66 Date: Sat, 18 Apr 2015 22:43:20 +0100 Subject: [PATCH] move quicksort to internal namespace --- octa/algorithm.h | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/octa/algorithm.h b/octa/algorithm.h index 71bba2c..e6abd32 100644 --- a/octa/algorithm.h +++ b/octa/algorithm.h @@ -47,33 +47,26 @@ namespace octa { U comp; bool operator()(const T &v) const { return comp(v, val); } }; - } - template - void quicksort(R range, C compare) { - if (range.length() <= 10) { - insertion_sort(range, compare); - return; + template + void quicksort(R range, C compare) { + if (range.length() <= 10) { + insertion_sort(range, compare); + return; + } + typename RangeTraits::reference p = range[range.length() / 2]; + swap(p, range.last()); + R r = partition(range, UnaryCompare{ p, compare }); + R l = range.slice(0, range.length() - r.length()); + swap(r.first(), r.last()); + quicksort(l, compare); + quicksort(r, compare); } - typename RangeTraits::reference p = range[range.length() / 2]; - swap(p, range.last()); - R r = partition(range, internal::UnaryCompare{ - p, compare - }); - R l = range.slice(0, range.length() - r.length()); - swap(r.first(), r.last()); - quicksort(l, compare); - quicksort(r, compare); - } - - template - void quicksort(R range) { - quicksort(range, Less::value>()); } template void sort(R range, C compare) { - quicksort(range, compare); + internal::quicksort(range, compare); } template