Q12. Write an code and algorithm to sort string of characters in dictionary order

Solution : Given a string contain lowercase character from a to z and our task is to sort them in dictionary order.

String :- A string is a sequence of characters terminated with a null character \0 .
For example: char lfc[] = “alfatechlab”;

Algorithm for sort string of characters in dictionary order

//Algorithm To Sort String Of Characters
START
Step 1 -> Take string as input str.
Step 2 -> Store the count of each character in one array ARR, index 0 corresponding to a and so on.
Step 3 -> Now repeat loop I till the end of array ARR
Step 4 -> Repeat inner loop on the basis of value of ARR[I]
Step 5 -> Print (‘a’ + I)
Step 6 -> End Inner loop
Step 7 -> End Loop
STOP

Code  for sort string of characters in dictionary order

Output

aaabcefhllt

Recommended Programs
Program to find factorial of a number
Program to count number of digits in a number