面试复习(C++)之快速排序

#include <iostream>

using namespace std;

void Quicksort(int *a,int low,int high)
{
if(low>high)
{
return;
}
int i=low;
int j=high;
int key=a[i];
while(i<j)
{
while(i<j&&a[j]>=key)
{
j--;
}
a[i]=a[j];
while(i<j&&a[i]<=key)
{
i++;
}
a[j]=a[i];
}
a[i]=key;
Quicksort(a,low,i-);
Quicksort(a,i+,high);
} int main()
{
int n=;
int a[];
for(int i=;i<n;i++)
{
cin>>a[i];
}
Quicksort(a,,n);
for(int j=;j<n;j++)
{
cout<<a[j]<<" ";
}
return ;
}
上一篇:2018-2019-2 网络对抗技术 20165324 Exp3:免杀原理与实践


下一篇:List stream 对象 属性去重