Question

In: Computer Science

C++ Write a routine that would receive a pointer to the top of the linked list...

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.

Solutions

Expert Solution

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;

}


Related Solutions

C++, Write a routine that would receive a pointer to the top of the linked list...
C++, Write a routine that would receive a pointer to the top of the linked list that has an integer for each node. Count all positive even integers in the linked list but make negatives into positives. Return the count negatives that became positives. Hint, use Node<ItemType>* to define pointers and use pointers to go through the linked list.
Problem Description: Using Python write a Singly‐Linked List (with only the Head pointer) that supports the...
Problem Description: Using Python write a Singly‐Linked List (with only the Head pointer) that supports the following operations: 1. Adding an element at the middle of the list. 2. Removing the middle element of the list (and return the data). 3. Adding an element at a given index. 4. Removing an element at a given index (and return the data). For #1 and #2, ignore the operations if the length of the list is an even number. For #3, if...
Objective: Manipulate the Linked List Pointer. Write a java subclass to extend LList.java. Provide a reverse...
Objective: Manipulate the Linked List Pointer. Write a java subclass to extend LList.java. Provide a reverse list method in the subclass to reverse the order of the linked list. Print the original linked list and the reverse ordered linked list at the end of program. You can use the gamescore.txt to test the reverse method. _____________________________________________________________________________________________________________________________________________________ /** Source code example for "A Practical Introduction to Data     Structures and Algorithm Analysis, 3rd Edition (Java)"     by Clifford A. Shaffer     Copyright 2008-2011 by...
You're given the pointer to the head node of a ordered linked list, an integer to...
You're given the pointer to the head node of a ordered linked list, an integer to add to the list. Write a function that inserts a number in the the list preserving its order. If the head pointer contains a null pointer that indicates an empty list. Function insertNode has the following parameters: head: a SinglyLinkedListNode pointer to the head of the list data: an integer value to insert as data in your new node Function prototype: SinglyLinkedListNode* insertNode(SinglyLinkedListNode* head,...
In Java, What is gained by having a Tail reference/pointer in your Linked List? A. The...
In Java, What is gained by having a Tail reference/pointer in your Linked List? A. The tail is superfluous and offers no benefits B. The tail allows us to speed up a few operations and gives us an end point to look for C.Since we have head and tail we can now do a Binary Search on the list D. It only makes deleting from the end of the list faster
In C++, Write a function to reverse the nodes in a linked list. You should not...
In C++, Write a function to reverse the nodes in a linked list. You should not create new nodes when you reverse the the linked list. The function prototype:          void reverse(Node*& head); Use the following Node definition: struct Node {    int data;    Node *next; }
1) a. Write down a C++ program which will create a list (simple linear linked list)...
1) a. Write down a C++ program which will create a list (simple linear linked list) of nodes. Each node consists of two fields. The first field is a pointer to a structure that contains a student id (integer) and a gradepoint average (float). The second field is a link. The data are to be read from a text file. Your program should read a file of 10 students (with student id and grade point average) and test the function...
Write down a C program which will create a list (simple linear linked list) of nodes....
Write down a C program which will create a list (simple linear linked list) of nodes. Each node consists of two fields. The first field is a pointer to a structure that contains a student id (integer) and a grade-point average (float). The second field is a link. The data are to be read from a text file. Your program should read a file of 10 students (with student id and grade point average) and test the function you wrote...
You are given a singly linked list. Write a function to find if the linked list...
You are given a singly linked list. Write a function to find if the linked list contains a cycle or not. A linked list may contain a cycle anywhere. A cycle means that some nodes are connected in the linked list. It doesn't necessarily mean that all nodes in the linked list have to be connected in a cycle starting and ending at the head. You may want to examine Floyd's Cycle Detection algorithm. /*This function returns true if given...
Write in C++: create a Doubly Linked List class that holds a struct with an integer...
Write in C++: create a Doubly Linked List class that holds a struct with an integer and a string. It must have append, insert, remove, find, and clear.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT