Sort a string without altering the position of vowels | Function to sort the string leaving the vowels unchanged ; Length of string S ; Traverse the string S ; Sort the string temp ; Pointer to traverse the sorted string of consonants ; Traverse the string S ; Driver Code
def sortStr ( S ) : NEW_LINE INDENT N = len ( S ) NEW_LINE temp = " " NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( S [ i ] != ' a ' and S [ i ] != ' e ' and S [ i ] != ' i ' and S [ i ] != ' o ' and S [ i ] != ' u ' ) : NEW_LINE INDENT temp += S [ i ] NEW_LINE DEDENT DEDENT if ( len ( temp ) ) : NEW_LINE INDENT p = list ( temp ) NEW_LINE p . sort ( ) NEW_LINE temp = ' ' . join ( p ) NEW_LINE DEDENT ptr = 0 NEW_LINE for i in range ( N ) : NEW_LINE S = list ( S ) NEW_LINE if ( S [ i ] != ' a ' and S [ i ] != ' e ' and S [ i ] != ' i ' and S [ i ] != ' o ' and S [ i ] != ' u ' ) : NEW_LINE INDENT S [ i ] = temp [ ptr ] NEW_LINE ptr += 1 NEW_LINE DEDENT print ( ' ' . join ( S ) ) NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT S = " geeksforgeeks " NEW_LINE sortStr ( S ) NEW_LINE DEDENT