#define_CRT_SECURE_NO_WARNINGS1#include<iostream>usingnamespace std;voidCount_sort(int* a,int n){//prepare c_array count the number of a_arry_elemint min=a[0], max=a[0];for(int i =0; i < n; i++){if(a[i]< min)
min = a[i];if(a[i]> max)
max = a[i];}int* c =newint[max - min +1];//avoid wasting space for(int i =0; i < max - min +1; i++)
c[i]=0;//inti c_arrayfor(int i =0; i <n; i++)
c[a[i]-min]++;//count the number of a_arry_elemint j =0;for(int i =0; i < max - min +1; i++)while(c[i]&&j<n){
a[j++]= i + min;
c[i]--;}}intmain(){int a[]={5,4,4,5,6,8,9,8,2,3,8,4,2,4};Count_sort(a,sizeof(a)/sizeof(int));for(constauto& e : a)
cout << e <<" ";
cout << endl;return0;}