不一样的做法
#include<bits/stdc++.h>
using namespace std;
int n;
set<int> a;
map<int,int> t;
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n;
while(n--){
int x;
cin>>x;
a.insert(x);
t[x]++;
}
for(int p:a)
for(int i=0;i<t[p];i++)
cout<<p<<' ';
return 0;
}以上代码排序时间复杂度是O(n),空间复杂度也是O(n),可以实现排序。