有没有大佬帮我看看这两个代码的区别呀,sort1是我写的,sort是可以过的,我感觉没区别呀。
#include <bits/stdc++.h>
using namespace std;
const int maxn = 10010;
int a[maxn];
void quick_sort1(int a[],int l,int r){
if(l >= r) return ;
int x = a[l],i= l,j = r;
while(i < j){
while(a[i] < x) i++;
while(a[j] > x) j--;
if(i < j) swap(a[i],a[j]),i++,j--;
}
quick_sort1(a,l,j);
quick_sort1(a,j+1,r);
}
void quick_sort(int a[],int l,int r){
if(l >= r) return ;
int x = a[l],i= l-1,j = r+1;
while(i < j){
do i++;while(a[i] < x);
do j--;while(a[j] > x);
if(i < j) swap(a[i],a[j]);
}
quick_sort(a,l,j);
quick_sort(a,j+1,r);
}
int main(){
// freopen("P1177_1.in","r",stdin);
// freopen("P1177_1.out","w",stdout);
int n;
cin >> n;
for(int i = 0;i < n;++i){
scanf("%d",&a[i]);
}
quick_sort(a,0,n-1);
for(int i = 0;i < n;++i){
printf("%d ",a[i] );
}
return 0;
}