38 template <
class T,
class LessThan>
44 for (i = 0; i < size-1; i++){
46 for (j = i+1; j < size; j++){
47 if (lt(array[j], array[best_i]))
50 tmp = array[i]; array[i] = array[best_i]; array[best_i] = tmp;
53 template <
class T>
static inline void selectionSort(T* array,
int size) {
56 template <
class T,
class LessThan>
57 void sort(T* array,
int size, LessThan lt)
63 T pivot = array[size / 2];
69 do i++;
while(lt(array[i], pivot));
70 do j--;
while(lt(pivot, array[j]));
74 tmp = array[i]; array[i] = array[j]; array[j] = tmp;
78 sort(&array[i], size-i, lt);
81 template <
class T>
static inline void sort(T* array,
int size) {
89 template <
class T,
class LessThan>
void sort(
vec<T>& v, LessThan lt) {
90 sort(
static_cast<T*
>(v), v.
size(), lt); }