forked from OctaForge/libostd
move quicksort to internal namespace
parent
4850e2454f
commit
f9a298c1b8
|
@ -47,33 +47,26 @@ namespace octa {
|
|||
U comp;
|
||||
bool operator()(const T &v) const { return comp(v, val); }
|
||||
};
|
||||
}
|
||||
|
||||
template<typename R, typename C>
|
||||
void quicksort(R range, C compare) {
|
||||
if (range.length() <= 10) {
|
||||
insertion_sort(range, compare);
|
||||
return;
|
||||
template<typename R, typename C>
|
||||
void quicksort(R range, C compare) {
|
||||
if (range.length() <= 10) {
|
||||
insertion_sort(range, compare);
|
||||
return;
|
||||
}
|
||||
typename RangeTraits<R>::reference p = range[range.length() / 2];
|
||||
swap(p, range.last());
|
||||
R r = partition(range, UnaryCompare<decltype(p), C>{ p, compare });
|
||||
R l = range.slice(0, range.length() - r.length());
|
||||
swap(r.first(), r.last());
|
||||
quicksort(l, compare);
|
||||
quicksort(r, compare);
|
||||
}
|
||||
typename RangeTraits<R>::reference p = range[range.length() / 2];
|
||||
swap(p, range.last());
|
||||
R r = partition(range, internal::UnaryCompare<decltype(p), C>{
|
||||
p, compare
|
||||
});
|
||||
R l = range.slice(0, range.length() - r.length());
|
||||
swap(r.first(), r.last());
|
||||
quicksort(l, compare);
|
||||
quicksort(r, compare);
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
void quicksort(R range) {
|
||||
quicksort(range, Less<typename RangeTraits<R>::value>());
|
||||
}
|
||||
|
||||
template<typename R, typename C>
|
||||
void sort(R range, C compare) {
|
||||
quicksort(range, compare);
|
||||
internal::quicksort(range, compare);
|
||||
}
|
||||
|
||||
template<typename R>
|
||||
|
|
Loading…
Reference in New Issue