升序题解
2024-10-04 20:20:45
发布于:北京
1阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int a[N],n;
void fun(int a[],int l,int r){
int x = a[l],i = l,j = r;
if(l >= r) return;
while(i < j){
while(i < j && a[j] >= x) j --;
a[i] = a[j];
while(i < j && a[i] <= x) i ++;
a[j] = a[i];
}
a[i] = x;
cout << a[0];
for(int i = 1;i < n;i ++) cout << " " << a[i];
cout << endl;
fun(a,l,i - 1);
fun(a,i + 1,r);
}
int main(){
cin >> n;
for(int i = 0;i < n;i ++) cin >> a[i];
fun(a,0,n - 1);
return 0;
}
这里空空如也
有帮助,赞一个