-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.cpp
38 lines (34 loc) · 883 Bytes
/
code.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// to print array with sorted strings
#include<bits/stdc++.h>
using namespace std;
string arr_str[] = {"samir", "gyawali", "algorithm", "sorted", "string"};
int arr_size = 5;
string copy_sorted[][50] = {0}; // array with sorted string {"aimrs", "aagilwy", ....}
char sorted_string[] = {0}; //each sorted string
string sort(string text, int size){
int hasharr[25] = {0};
int index;
for(int i=0; i<size; i++){
index = text[i] - 'a';
hasharr[index] = hasharr[index]+1;
}
for(int i=0; i<25; ++i){
for(int j=0; j<hasharr[i]; ++j){
sorted_string[i] = char(i+'a');
cout<<char(i+'a');
}
}
return sorted_string;
}
int main(){
for(int i=0; i<arr_size; ++i){
int size = sizeof(arr_str[i])/sizeof(char);
copy_sorted[i] = sort(arr_str[i], size);
cout<<copy_sorted[i];
}
for(int i=0; i<arr_size; ++i){
cout<<copy_sorted[i];
}
// sort("samir", 5);
return 0;
}