【算法介绍】
桶排序的思想:
若待排序的值在一个有限范围内(整型)时,可设计有限个有序桶,桶号就是待排序的值。
之后,将待排序的值依次装入对应的有序桶中(重复值都装入对应的桶),然后顺序输出各桶的值,便得到有序的序列。
【算法代码】
#include<bits/stdc++.h>
using namespace std;
const int maxn=500;
int t[maxn];
int main() {
int n;
cin>>n;
int x; //x is less than maxn
for(int i=1; i<=n; i++) {
cin>>x;
t[x]++;
}
for(int j=1; j<=maxn; j++) {
while(t[j]>0) {
cout<<j<<" ";
t[j]--;
}
}
return 0;
}
/*
in:
10
20 40 32 67 40 20 89 300 400 15
out:
15 20 20 32 40 40 67 89 300 400
*/
【参考文献】
https://blog.csdn.net/sdau20171989/article/details/79198443
https://blog.csdn.net/qq_27124771/article/details/87651495