Sort an Array of Strings according to the number of Vowels in them | C # implementation of the approach ; Function to check the Vowel ; Returns count of vowels in str ; if ( isVowel ( str [ i ] ) ) Check for vowel ; Function to sort the array according to the number of the vowels ; Vector to store the number of vowels with respective elements ; Inserting number of vowels with respective strings in the vector pair ; Sort the vector , this will sort the pair according to the number of vowels ; Print the sorted vector content ; Driver code
using System ; using System . Collections . Generic ; class GFG { static bool isVowel ( char ch ) { ch = char . ToUpper ( ch ) ; return ( ch == ' A ' ch == ' E ' ch == ' I ' ch == ' O ' ch == ' U ' ) ; } static int countVowels ( string str ) { int count = 0 ; for ( int i = 0 ; i < str . Length ; i ++ ) ++ count ; return count ; } static void sortArr ( string [ ] arr , int n ) { List < Tuple < int , string > > vp = new List < Tuple < int , string > > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { vp . Add ( new Tuple < int , string > ( countVowels ( arr [ i ] ) , arr [ i ] ) ) ; } vp . Sort ( ) ; for ( int i = 0 ; i < vp . Count ; i ++ ) Console . Write ( vp [ i ] . Item2 + " ▁ " ) ; } static void Main ( ) { string [ ] arr = { " lmno " , " pqrst " , " aeiou " , " xyz " } ; int n = arr . Length ; sortArr ( arr , n ) ; } }