This problem solution from a bold idea
Bucket sort has a high speed, it is a space for time algorithm, has great limitations, can not be used too much data row
Thus, instead of using map array, time for space, seeks to expand practical
In C ++ STL map <int, int> can be used as an array, analog bucket sort, but because the map is a dynamic application storage space, the equivalent of automatic discrete, solve previously wasted space
Iterative traversal save time map, a blank portion is skipped
The next code on guard against shock, (operation or something, is very simple)
#include<bits/stdc++.h>
#define getc getchar()
using namespace std;
map<int,int> k;//定义k桶
int n;
map<int,int>::iterator it;//定义迭代器it
int s[60000];
int read()//快读 ,不解释了
{
int x=0;
char c;
for(c=getc;c>'9'||c<'0';c=getc);
for(;c<='9'&&c>='0';c=getc)x=x*10+c-'0';
return x;
}
int main()
{
n=read();
for(int i=1;i<=n;i++)
{
int tis;
tis=read();
k[tis]++;//装入桶内
}
for(it=k.begin();it!=k.end();it++)//迭代器遍历,不了解请百度
{
for(int i=1;i<=it->second;i++)//map内元素是pair类型的,例如a[123]=666; 则first指123,second指666,以此类推
{//迭代器指向该元素的出现次数second
int sum=it->first;//迭代器指向该元素first
printf("%d ",sum);//输出
}
}
}