Skip to content

Instantly share code, notes, and snippets.

@mirsahib
Created March 2, 2018 06:03
Show Gist options
  • Save mirsahib/7a4c7cc8ac495acd7edf5d6a9f96e6d7 to your computer and use it in GitHub Desktop.
Save mirsahib/7a4c7cc8ac495acd7edf5d6a9f96e6d7 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <vector>
using namespace std;
vector<string> count_sort(int b[],int s,vector<string>arr,int pass){
string c[10];
for(int i=1;i<10;i++){
b[i]=b[i-1]+b[i];
}
for(int i=0;i<arr.size();i++){
int index = arr[i][pass]-'0';
int k = b[index];
c[--b[index]]=arr[i];
}
vector<string>result(c,c+10);
int k=0;
return result;
}
int main()
{
string a[10]={"575","123","000","234","908","644","367","490","729","089"};
int b[10];
for(int i=0;i<10;i++)b[i]=0;
vector<string>arr(a,a+10);
for(int i=2;i>=0;i--){
for(int j=0;j<10;j++){
int index = a[j][i]-'0';
b[index]++;
}
arr = count_sort(b,10,arr,i);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment