Sort a string without altering the position of vowels | C # program for the above approach ; 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
using System ; using System . Collections . Generic ; public class GFG { static void sortStr ( String str ) { char [ ] S = str . ToCharArray ( ) ; int N = S . Length ; List < char > temp = new List < char > ( ) ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] != ' a ' && S [ i ] != ' e ' && S [ i ] != ' i ' && S [ i ] != ' o ' && S [ i ] != ' u ' ) temp . Add ( S [ i ] ) ; } if ( temp . Count != 0 ) temp . Sort ( ) ; int ptr = 0 ; for ( int i = 0 ; i < N ; i ++ ) { if ( S [ i ] != ' a ' && S [ i ] != ' e ' && S [ i ] != ' i ' && S [ i ] != ' o ' && S [ i ] != ' u ' ) S [ i ] = temp [ ptr ++ ] ; } Console . WriteLine ( new String ( S ) ) ; } public static void Main ( String [ ] args ) { String S = " geeksforgeeks " ; sortStr ( S ) ; } }