int main() { char B[20]; strcpy(B, "RRRGGGRRR"); three_way_partition(B, strlen(B)); printf("%s", B); return 0; }
three_way_quicksort(int *a, int s, int e) { int l = 0, r = 0; if(s < e - 1){ three_way_partition(a, s, e, &l, &r); three_way_quicksort(a, s, l); three_way_quicksort(a, r, e); } }
static void three_way_qsort(int arr[], int left, int right) { if (left < right) { int left_range; int right_range; three_way_partition(arr, left, right, &left_range, &right_range); three_way_qsort(arr, left, left_range-1); three_way_qsort(arr, right_range+1, right); } }
static void quick_sort(std::vector<int> &vec, int l, int r) { if( l >= r ) return; //randomize int t = rand()%(r-l+1)+l; std::swap(vec[l], vec[t]); //int p = partition(vec, l, r); std::pair<int, int> p = three_way_partition(vec, l ,r); quick_sort(vec, l, p.first-1); quick_sort(vec, p.second, r); }