I have the following code, but this only works for unsigned ints, and my goal is to write code that will work for all ints ...
void CountingSort(vector<int> & a, vector<int> & b) { int k=*max_element(a.begin(),a.end()); k++; vector <int> c(k); for (int i=0;i<a.size();i++) c[a[i]]++; for (int i=1;i<k;i++) c[i]=c[i]+c[i-1]; for (int i=0;i<a.size();i++) { b[c[a[i]]-1]=a[i]; c[a[i]]--; } }
How can I change this to work for all integral types?
user530664
source share