Question: C++ Write a program that creates a linked list of integers, and a function that returns true if the number of nodes in the list

C++ Write a program that creates a linked list of integers, and a function that returns true if the number of nodes in the list is even, and false if it is odd.

Requirements:

1. Implement a lengthIsEven function: bool lengthIsEven(Node *head); // example declaration This function should return true if the number of nodes in the linked list is even, and false if it is odd. Examples: * If the list is 3 -> 9 -> 2 -> 4 -> NULL , calling lengthIsEven(head) should return true . * If the list is 3 -> 9 -> 2 -> NULL , calling lengthIsEven(head) should return false . * If the list is NULL , calling lengthIsEven(head) should return true .

2. Write a main function that creates a linked list of integers, then calls the function defined in part (1) to determine if the length of the list is even or odd. Call it on multiple lists to show that it works in all cases, and print out the results.

3. Test your function to make sure that it works in every case, no matter how many nodes are in the linked list.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!