Question
Recursive remove() operation on a linked list based on the Node class In this lab, you will try to determine how to implement a linked
Recursive remove() operation on a linked list based on the Node class In this lab, you will try to determine how to implement a linked list operation recursively. In particular, you will implement the following operations recursively: e display() will display the contents of a linked list in reverse order; since the provided insert() functions inserts items at the front of the list, the items will be in reverse order, so to print them in the correct order the list will be displayed in reverse; and remove() will remove a target value from the linked list if it is in the list; otherwise, it does nothing to the list.
The function prototypes for these functions are provided in main.cpp below. Instructions for this zyLab are also provided as comments in main.cpp below. Design your function main() so that input is provided as two lists of unsigned integers terminated by a negative value. Hence, the following input: 1 2 3 4 5 -1 1 3 5 -1 means the list will contain the values 1,2,3,4,5 and the values 1, 3, and 5 will be removed from the list, resulting in the list containing the values 2,4. Your function main() should display the original list, perform the removes, and then display the list again after all the remove operations have completed. So, for the sample input above, your program's output should be: Contents: 1 2 3 4 5 After remove() operations: 24
main - Notepad File Edit Format View Help // Function to insert an item into the front of a linked list template class T > void insert( Node* &headPtr , const T& entry ) // Create a new node and have the next pointer point to current front Node *newNodePtr = new Node( entry , headPtr ); // Current front now becomes this new node headPtr = newNodePtr; } // Recursive function to remove an item from a linked list // Returns true if the operation was done; false, otherwise template bool remove( Node* &nodePtr T target ) { // YOUR CODE GOES HERE }
> // Recursive function to display the contents of a linked list // in the reverse order. template void display( Node *currNodePtr ) { // YOUR CODE GOES HERE CHECK YOUR NOTES! int main() IL (1) Declare an empty linked list of unsigned values 17 based on the Node class and call it myList // (2) Read in values from standard input. Non-negative // values are inserted into my List and a negative 17 value terminates input. // (3) Display the contents of the linked list myList // in the order they were entered (hence, the display() // function displays myList in reverse order! // (4) Read in values from standard input. Non-negative R. Cnn Wir main - Notepad File Edit Format View Help { // YOUR CODE GOES HERE
} // Recursive function to display the contents of a linked list // in the reverse order. template void display( Node *currNodePtr ) { // YOUR CODE GOES HERE CHECK YOUR NOTES! } int main() { // (1) Declare an empty linked list of unsigned values // based on the Node class and call it myList Il (2) Read in values from standard input. Non-negative // values are inserted into myList and a negative // value terminates input. IL (3) Display the contents of the linked list myList I in the order they were entered (hence, the display() I/ function displays myList in reverse order! II (4) Read in values from standard input. Non-negative 1/ values are removed from myList and a negative // value terminates input. //
: : Node () : next (nullptr) { 11 end default constructor template Node: :\" v:shapes=\"Picture_x0020_122\">
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started