#include <iostream>

using namespace std;

/** Quick Sort
 *
 * split: cmp && swap
 * left
 * right
 *
 */
template <typename T>
int split(T* a, int low, int high) {
while(low < high) {
        while(a[low] <= a[high] && low < high){
            low ++;
        }
        swap(a[low], a[high]); /// swap
        while (a[low] <= a[high] && low < high){
            high --;
        }
        swap(a[low], a[high]); ///swap
    }
    return low;
}

template <typename T>
void quickSort(T* a, int low, int high) {
    if(low < high) {
        int key = split(a, low, high);
        cout << "key:" << key <<endl;
        quickSort(a,low, key-1);
        quickSort(a,key+1, high);
    }
}

 

相关文章:

  • 2022-01-24
  • 2021-07-14
  • 2021-05-30
  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
猜你喜欢
  • 2021-09-16
  • 2021-05-25
  • 2021-05-25
  • 2021-12-29
  • 2021-11-17
  • 2021-10-26
相关资源
相似解决方案