#ifndef QUICKSORT #define QUICKSORT #include #include #include template int Partition(std::vector & ary, int & low, int & high) { T pivot{ary[(high+low)/2]}; int i{low-1}, j{high+1}; while (i < j) { do { i++; } while (ary[i] < pivot) ; do { j--; } while (ary[j] > pivot); if (i < j) { std::swap(ary[i], ary[j]); } } return j; } template void QuickSort(std::vector & ary, int low=0, int high=-1) { if (high == -1) { high = static_cast(ary.size())-1; } if (low >=0 and high >= 0 and low < high) { int pos = Partition(ary, low, high); QuickSort(ary, low, pos); QuickSort(ary, pos+1, high); } } #endif