1 #include<iostream> 2 using namespace std; 3 4 5 void Counting_Sort(int a[], int b[], int n, int k) 6 { 7 int *c = new int[k]; 8 for (int i = 0; i < k; i++) 9 c[i] = 0; 10 for (int i = 1; i <= n; i++) 11 c[a[i]]++; 12 for (int i = 1; i < k; i++) 13 c[i] = c[i] + c[i - 1]; 14 for (int j = n; j >= 1; j--) 15 { 16 int u = a[j]; 17 int d = c[u]; 18 b[d] = a[j]; 19 c[u] = d - 1; 20 } 21 } 22 23 24 25 void main() 26 { 27 int a[11]; 28 int b[11]; 29 for (int i = 1; i < 11; i++) 30 a[i] = 11 - i; 31 Counting_Sort(a, b, 10, 11); 32 for (int i = 1; i < 11; i++) 33 cout << b[i] << endl; 34 }