Print the frequency of each character in Alphabetical order | C ++ implementation of the approach ; Function to print the frequency of each of the characters of s in alphabetical order ; To store the frequency of the characters ; Update the frequency array ; Print the frequency in alphatecial order ; If the current alphabet doesn 't  appear in the string ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; const int MAX = 26 ; void compressString ( string s , int n ) { int freq [ MAX ] = { 0 } ; for ( int i = 0 ; i < n ; i ++ ) { freq [ s [ i ] - ' a ' ] ++ ; } for ( int i = 0 ; i < MAX ; i ++ ) { if ( freq [ i ] == 0 ) continue ; cout << ( char ) ( i + ' a ' ) << freq [ i ] ; } } int main ( ) { string s = " geeksforgeeks " ; int n = s . length ( ) ; compressString ( s , n ) ; return 0 ; }