In: Computer Science
C++
Write a routine that would receive a pointer to the top of the linked list that has a string for each node. Count all strings that start with a vowel (assume lowercase) in the linked list but tack on a “?” on all non-vowel strings. Return the count. Hint, use Node<ItemType>* to define pointers and use pointers to go through the linked list.
CODE:
int getVowelCount(Node<string>* head)
{
int count = 0;
while(head)
{
//Check if the string starts with a vowel for the current node
if(head->val[0] == 'a'||
head->val[0] == 'e'||
head->val[0] == 'i'||
head->val[0] == 'o'||
head->val[0] == 'u')
{
//If yes then increment the count
++count;
}
else
{
//append ? to the non vowel string
head->val += "?";
}
head = head->next;
}
//return the count
return count;
}