快速排序

#include< iostream>

using namespace std;

void quick_sort(int* num,int left,int right)
{

 if(left < right)
{

    int low=left;
    int high=right;
    int key=num[low];
    while(low< high)
  {
    while(low< high&&num[high]>=key)
        --high;
    num[low]=num[high];

    while(low< high&&num[low]<=key)
        ++low;
    num[high]=num[low];
  }

   num[low]=key;
   //遞歸
   quick_sort(num,left,low-1);
   quick_sort(num,low+1,right);
}

}

int main(void)
{

int num[9]={2,5,9,1,7,3,18,20,11};

quick_sort(num,0,8);

for(int i=0;i<9;++i)

return 0;

}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章