-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse_vowel_of_string.cpp
More file actions
43 lines (40 loc) · 918 Bytes
/
reverse_vowel_of_string.cpp
File metadata and controls
43 lines (40 loc) · 918 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
#include <string>
using namespace std;
class Solution {
public:
bool isvowel(char &c) {
if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' ||
c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
return 1;
}
return 0;
}
string reverseVowels(string s) {
int n = s.length();
int i = 0;
int j = n - 1;
while (i < j) {
if (!isvowel(s[i])) {
i++;
}
else if (!isvowel(s[j])) {
j--;
}
else {
swap(s[i], s[j]);
i++;
j--;
}
}
return s;
}
};
int main() {
Solution obj;
string str;
cout << "Enter string: ";
cin >> str;
cout << "After reversing vowels: " << obj.reverseVowels(str) << endl;
return 0;
}