Created
March 2, 2018 06:03
-
-
Save mirsahib/7a4c7cc8ac495acd7edf5d6a9f96e6d7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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