54 template<
class T,
class CMPR>
55 void partition(T *data,
size_t n,
size_t &pivot, CMPR &cmp) {
64 ptpart = data + (rand() % n);
66 ptpart = data + (random() % n);
74 for (p = data - 1, q = data + n; ; ) {
78 }
while (cmp.compare(*q, tpart) > 0);
81 }
while (cmp.compare(*p, tpart) < 0);
98 template<
class T,
class CMPR>
102 for (p = data + 1; p < data + n; p++) {
103 for (q = p - 1, test = *p; (cmp.compare(*q, test) > 0); q--) {
118 template<
class T,
class CMPR>
119 void quicksort(T *data,
size_t n, CMPR &cmp,
size_t min_len = 20) {
128 quicksort(data, pivot + 1, cmp, min_len);
129 quicksort(data + pivot + 1, n - pivot - 1, cmp, min_len);
135 #endif // _QUICKSORT_H void partition(T *data, size_t n, size_t &pivot, CMPR &cmp)
void insertionsort(T *data, size_t n, CMPR &cmp)
void quicksort(T *data, size_t n, CMPR &cmp, size_t min_len=20)