Your algorithm is a little goofy. I think a more intuitive algorithm would match the way one might do it manually: Find the first non-vowel and mark it y, this is the end of the vowel half
Find the next vowel and mark it x
Swap the characters at y and x
Increment y
Repeat at 2 until x reaches the end of the list
This is easily translated to C++, and only requires a way to determine whether the specified character is a vowel:
void vowel_partition(char a[], int n)
{
int x = 0;
// Find the first non-vowel
while (x < n && is_vowel(a[x]))
++x;
// Swap in any remaining vowels
for (int y = x; x < n; x++) {
if (is_vowel(a[x])) {
std::swap(a[x], a[y]);
++y;
}
}
} Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401