Modify the string by swapping continuous vowels or consonants | C ++ implementation of the above approach ; Function to check if a character is a vowel ; Function to swap two consecutively repeated vowels or consonants ; Traverse through the length of the string ; Check if the two consecutive characters are vowels or consonants ; swap the two characters ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool isVowel ( char c ) { c = tolower ( c ) ; if ( c == ' a ' c == ' e ' c == ' i ' c == ' o ' c == ' u ' ) return true ; return false ; } string swapRepeated ( string str ) { for ( int i = 0 ; i < str . length ( ) - 1 ; i ++ ) { if ( ( isVowel ( str [ i ] ) && isVowel ( str [ i + 1 ] ) ) || ( ! isVowel ( str [ i ] ) && ! isVowel ( str [ i + 1 ] ) ) ) swap ( str [ i ] , str [ i + 1 ] ) ; } return str ; } int main ( ) { string str = " geeksforgeeks " ; cout << swapRepeated ( str ) ; return 0 ; }