text: Reverse vowels in a given string | C ++ program to reverse order of vowels ; utility function to check for vowel ; Function to reverse order of vowels ; Start two indexes from two corners and move toward each other ; swapping ; Driver function
code: #include <bits/stdc++.h> NEW_LINE using namespace std ; bool isVowel ( char c ) { return ( c == ' a ' c == ' A ' c == ' e ' c == ' E ' c == ' i ' c == ' I ' c == ' o ' c == ' O ' c == ' u ' c == ' U ' ) ; } string reverseVowel ( string str ) { int i = 0 ; int j = str . length ( ) - 1 ; while ( i < j ) { if ( ! isVowel ( str [ i ] ) ) { i ++ ; continue ; } if ( ! isVowel ( str [ j ] ) ) { j -- ; continue ; } swap ( str [ i ] , str [ j ] ) ; i ++ ; j -- ; } return str ; } int main ( ) { string str = " hello ▁ world " ; cout << reverseVowel ( str ) ; return 0 ; }