In: Computer Science
Write a function that takes a string, returns void and has the effect of shifting the vowels of the string to the left. For example, if the input string was “hello class”, then after calling this function the string should contain “holla cless” (note that the first vowel is moved to the location of the last vowel). You can use an auxillary string if you want, but a nicer solution would work “in-place”
FUNCTION :
void function(string &str)
{
string s="";
for(int i=0;i<str.size();i++)
{
if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u')
s=s+str[i];
}
char a=s[0];
for(int i=0;i<s.size()-1;i++)
s[i] = s[i+1];
s[s.size()-1]=a;
int k=0;
for(int i=0;i<str.size();i++)
{
if(str[i]=='a'||str[i]=='e'||str[i]=='i'||str[i]=='o'||str[i]=='u')
{
str[i] = s[k++];
}
}
}
EXAMPLE :
OUTPUT OF ABOVE CODE :