#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int partion(int s[], int l, int r) //返回调整后基准数的位置
{
int i = l, j = r;
int x = s[l]; //s[l]即s[i]就是第一个坑
while (i < j)
{
while(i<j&&s[j]>=x)
j--;
if(i<j)
{
s[i]=s[j];
i++;
}
while(i<j&&s[i]<=x)
i++;
if(i<j)
{
s[j]=s[i];
j--;
}
}
s[i] = x;
return i;
}
void quickSort(int a[],int left,int right)
{
if(left<right)
{
int pos=partion(a,left,right);
quickSort(a,left,pos-1);
quickSort(a,pos+1,right);
}
}
int main()
{
int a[]={1,3,2,6,7,4,5,2};
quickSort(a,0,7);
for(int i=0;i<=7;i++)
{
cout<<a[i]<<" "<<endl;
}
system("pause");
return 0;
}
#include <cstdlib>
#include <vector>
using namespace std;
int partion(int s[], int l, int r) //返回调整后基准数的位置
{
int i = l, j = r;
int x = s[l]; //s[l]即s[i]就是第一个坑
while (i < j)
{
while(i<j&&s[j]>=x)
j--;
if(i<j)
{
s[i]=s[j];
i++;
}
while(i<j&&s[i]<=x)
i++;
if(i<j)
{
s[j]=s[i];
j--;
}
}
s[i] = x;
return i;
}
void quickSort(int a[],int left,int right)
{
if(left<right)
{
int pos=partion(a,left,right);
quickSort(a,left,pos-1);
quickSort(a,pos+1,right);
}
}
int main()
{
int a[]={1,3,2,6,7,4,5,2};
quickSort(a,0,7);
for(int i=0;i<=7;i++)
{
cout<<a[i]<<" "<<endl;
}
system("pause");
return 0;
}