Improving the Quick sort

前端 未结 14 1319
终归单人心
终归单人心 2021-02-05 22:33

If possible, how can I improve the following quick sort(performance wise). Any suggestions?

void main()
    {
      quick(a,0,n-1);
    }

    void quick(i         


        
14条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-05 22:55

    1. You can a eliminate recuriosn overhead by using QuickSort with Explicit Stack

      void quickSort(int a[], int lower, int upper)
      {
          createStack(); 
          push(lower); 
          push(upper);
      
          while (!isEmptyStack()) {
          upper=poptop();
          lower=poptop();
             while (lower
    2. You can use better pivot selection technique such as:

      1. median of 3
      2. median of medians
      3. random pivot

提交回复
热议问题