桶排序

Roman edited 3 年前

牺牲空间以换取时间,将需要排序的数组中的元素作为另一大数组(初始化为0)的下标,输入时每次读取到数字就大数组中元素对应+1,输出时扫描大数组,输出元素中的数字个下标

include

include

using namespace std;
int main() {
int x,n;
cin>>n;
int a[100]= {0};
for (int i=0; i>x;
a[x]++;
}
for(int i=0; i<100; i++) {//扫描大数组
for(int m=1;m<=a[i];m++){
cout<<i<<” “;}

}

}

Comments