Sort the given string using character search | C ++ implementation to sort the given string without using any sorting technique ; function to sort the given string without using any sorting technique ; to store the final sorted string ; for each character ' i ' ; if character ' i ' is present at a particular index then add character ' i ' to ' new _ str ' ; required final sorted string ; Driver program to test above
#include <bits/stdc++.h> NEW_LINE using namespace std ; string sortString ( string str , int n ) { string new_str = " " ; for ( int i = ' a ' ; i <= ' z ' ; i ++ ) for ( int j = 0 ; j < n ; j ++ ) if ( str [ j ] == i ) new_str += str [ j ] ; return new_str ; } int main ( ) { string str = " geeksforgeeks " ; int n = str . size ( ) ; cout << sortString ( str , n ) ; return 0 ; }