#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<cmath>
#include<cassert>
#include<cstring>
#include<iomanip>
using namespace std;
#define FOR(i,a,b) for( int i = (a) ; i <= (b) ; i ++)
#define FF(i,a) for( int i = 0 ; i < (a) ; i ++)
#define FFD(i,a,b) for( int i = (a) ; i >= (b) ; i --)
#define S64(a) scanf(in64,&a)
#define sf(a) scanf("%d",&a)
#define LL(a) ((a)<<1)
#define RR(a) (((a)<<1)+1)
#define PB push_back
#define PF push_front
#define X first
#define Y second
#define CL(Q) while(!Q.empty())Q.pop()
#define MM(name,what) memset(name,what,sizeof(name))
#define MC(a,b) memcpy(a,b,sizeof(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define read freopen("in.txt","r",stdin)
#define write freopen("out.txt","w",stdout)
#define MAX_SIZE 10000+1
int num[MAX_SIZE];
int temp[MAX_SIZE];
int partion(int num[],int left,int right)
{
int i,j,index;
index = num[left];
i=left;
j=right;
while (i<j) // 双向扫描算法
{
while(num[i]<=index&&i<right)
i++;
while(num[j]>=index&&j>left)
j--;
if(i>=j)break;
swap(num[i],num[j]);
}
swap(num[left],num[j]);// 从小到大排序注意是 交换 j 和 index 位置!
return j;
}
void quick_sort(int num[],int lo,int hi)
{
if (lo<hi)
{
int x = partion(num,lo,hi);
quick_sort(num,lo,x-1);
quick_sort(num,x+1,hi);
}
}
int main()
{
int i;
int num[] {6,1,2,5,9,10,11};
quick_sort(num,0,6);
for(i=0;i<6;i++)
printf("%d\n",num[i]);
return 0;
}
网友评论