/*** * _ __ ___ _ * | |/ /___ ___ _ __ / __|__ _| |_ __ * | ' namespace algo { //Partition routine for quicksort template static int __partition(T list[], int start, int end) { int pivotIndex = random_range(start, end); T pivot = list[pivotIndex]; //Swapping pivot element with element at start swap(list[start], list[pivotIndex]); int i = start + 1; int j = end; while (i <= j) { while ((i <= end) && (list[i] <= pivot)) { ++i; } while ((j >= start) && (list[j] > pivot)) { --j; } if (i < j) { swap(list[i], list[j]); } } swap(list[start], list[j]); return j; } //quickSort Routine template static void quickSort(T list[], int start, int end) { if (start < end) { int pivotIndex = __partition(list, start, end); quickSort(list, start, pivotIndex - 1); quickSort(list, pivotIndex + 1, end); } } }//end of namespace algo #endif //end of quickSort.h