Modify string by rearranging vowels in alphabetical order at their respective indices | Function to arrange the vowels in sorted order in the string at their respective places ; Store the size of the string ; Stores vowels of string S ; Traverse the string , S and push all the vowels to string vow ; If vow is empty , then print S and return ; Sort vow in alphabetical order ; Traverse the string , S ; Replace S [ i ] with vow [ j ] iif S [ i ] is a vowel , and increment j by 1 ; Print the string ; Driver Code
def sortVowels ( S ) : NEW_LINE INDENT n = len ( S ) ; NEW_LINE vow = " " ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( S [ i ] == ' a ' or S [ i ] == ' e ' or S [ i ] == ' i ' or S [ i ] == ' o ' or S [ i ] == ' u ' ) : NEW_LINE INDENT vow += S [ i ] ; NEW_LINE DEDENT DEDENT if len ( vow ) == 0 : NEW_LINE INDENT print ( S , end = " " ) ; NEW_LINE return ; NEW_LINE DEDENT vow = list ( vow ) ; NEW_LINE vow . sort ( ) ; NEW_LINE j = 0 ; NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( S [ i ] == ' a ' or S [ i ] == ' e ' or S [ i ] == ' i ' or S [ i ] == ' o ' or S [ i ] == ' u ' ) : NEW_LINE INDENT S [ i ] = vow [ j ] ; NEW_LINE j += 1 ; NEW_LINE DEDENT DEDENT print ( " " . join ( S ) , end = " " ) ; NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT S = " geeksforgeeks " ; NEW_LINE sortVowels ( list ( S ) ) ; NEW_LINE DEDENT