直接桶排序即可,我用的是 map。
#include<bits/stdc++.h>
using namespace std;
map<int,int>vis;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;i++){
int x;
cin>>x;
vis[x]++;
}
for(auto i:vis){
for(int j=1;j<=i.second;j++){
cout<<i.first<<" ";
}
}
return 0;
}