21 #ifndef ELM_QUICKSORT_H_
22 #define ELM_QUICKSORT_H_
24 #include <elm/compare.h>
29 template <
class A,
class C = Comparator<
typename A::t> >
31 static const int max = 300;
35 beg[0] = 0; end[0] =
array.count();
37 L = beg[i]; R = end[i] - 1;
41 while(C::compare(
array[R], piv) >= 0 && L < R) R--;
if(L < R)
array[L++] =
array[R];
42 while(C::compare(
array[L], piv) <= 0 && L<R) L++;
if (L < R)
array[R--] =
array[L];
44 array[L] = piv; beg[i+1] = L+1; end[i+1] = end[i]; end[i++] = L;
45 if(end[i] - beg[i] > end[i-1] - beg[i-1]) {
46 swap = beg[i]; beg[i] = beg[i-1]; beg[i-1] =
swap;
47 swap = end[i]; end[i] = end[i-1]; end[i-1] =
swap;