#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int arr[10] = { 0,9,4,7,7,5,6,2,2,1 };//元素值都在arr的arr.size-1内!!本例元素就不能含有10
int B[10],C[10];//保证C的维度不大于arr的维度
for (int i = 0; i < 10; i++)
cout << arr[i] << endl;
for (int i = 0; i < 10; i++)
C[i] = 0;
for (int j = 0; j < 10; j++)
C[arr[j]] = C[arr[j]] + 1;
for (int i = 1; i < 10; i++)
C[i] = C[i] + C[i - 1];
for (int j = 9; j >= 0; j--)
{
B[C[arr[j]]-1] = arr[j];//这里是B[C[arr[j]]-1]而不是B[C[arr[j]]],理由是因为下标从0开始
C[arr[j]] = C[arr[j]] - 1;
}
cout << "排序后:" << endl;
for (int i = 0; i < 10; i++)
cout << B[i] << endl;
return 0;
}