快速排序

来源:互联网 发布:网络优化前台累吗 编辑:程序博客网 时间:2024/05/22 14:58

#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;

}

0 0
原创粉丝点击