Answered step by step
Verified Expert Solution
Question
1 Approved Answer
its simple but there is a lot of pictures just to be clear of the requirements and output, please solve this using C++ language 1.
its simple but there is a lot of pictures just to be clear of the requirements and output, please solve this using C++ language
1. Create a new project called Lab4_Link List Project2. 2. Create a Node class & a LinkedList class, and program the tasks in the main method. 3. Taskl: Write and test a method named swapFirstLast() which swaps the data of first and last nodes in the linked list. Note: If list is empty or contains only one node, your code should display error message accordingly. Hint: Use following method header: void swapFirstLasto! 1 4. Task2: Write and test a method named countEvenOddNodes) which counts and displays number of even nodes as well as number of an odd nodes present in the linked list. Note: If list is empty, your code should display error message accordingly. Hint: Use following method header: void countEvenoddNodes (1) int evenNodes = 0; int oddNodes = 0; cout Task4: deleteNodeAfter() "; //you will complete code here 8. When you run this program, it will display the following screen: Sample run 1: If the list is empty. How many values do you want to sesert: Printing All Wodes: The 11 e empty Collodes) Beroe cannot couns nodes the list is empty princivanlode( Beroe cannot peins even nodes she lie is empty! Takl: SLADI Error: Cannot swap the 2.6 has less than we nodes Tuak: convenoddeden The li is empty Number of Even made in the litt Number of Odd not in the 2136 iso Tak adatai Beroe cannot add node afsee the list is unpur Take: delede text Error: cannot delese node ser the 26 septy Samples run 2: * If the list has one element. 1) Printing All Nodes: 12, countNodes) Number of nodes in the linked list is 1 printEvenNodes() Printing Even Nodes. 12 Taski: swapFirst Last Error: cannot swap (the list has less than two nodes) Task2: countEvenOddfodes() Number of Even nodes in the list is 1 Number of Odd nodes in the list is o Task3: addNodeAfter) Please enter the node data After which you want to add a new node: 30 Error: There is no node in the List with 30 Taske: deleteNodeAtter) Please enter the node data After which you want to delete a node: 30 Error: There is no node in the List with 30 Sample run 3: If the user inserts 2 elements How many values do you want to insert: 2 value 1: 10 10 was successfully inserted into the list. value 2:7 7 was successfully inserted into the list. Printing All Nodes: 7, 10, AA countNodes (0) Number of nodes in the linked list is 2 AAA printEvenNodes () Printing Even Nodes. 10. AAA Taskl: swapFirstLast) First and last element had been swaped successfully! 10, 7, Task2: countEvenOddNodes) Number of Even nodes in the list is 1 Number of Odd nodes in the list is 1 Tasks: addNodeAtter Please Enter the node data after which you want to add a new node:7 New node have been added successfully! 10, 7, 14, Y VYV Task4: deleteNodeAfter() Please Enter the node data after which you want to delete a node: 10 Node have been deleted successfully! 10, 14, Sample run 4: If the user inserts more than 2 elements How many values do you want to insert: 6 value 1: 12 12 was successfully inserted into the list. value 2: 17 17 was successfully inserted into the list. value 3: 10 10 was successfully inserted into the list. value 4: 50 50 was successfully inserted into the list. value 5: 10 10 already exists in the 1185. Duplicates are not allowed. value 5: 20 20 was successfully inserted into the list. value 6: 30 30 was successfully inserted into the list. Drinting All Nodes: 10, 12, 17, 20, 30, 50, countNodes) Number of nodes in the linked list is 6 printEven Nodes() Printing Even Nodes. 10, 12, 20, 30, 50, Taski: swapTirtlast) First and last element had been awaped successfully! 50, 12, 17, 20, 30, 10, Task2: countEvenoddNodes) Number of Even nodes in the list is 5 Number of Odd nodes in the list is 1 Task3: addNoden text) Please enter the node data after which you want to add a new node:20 New node have been added successfully! 50, 12, 17, 20, 40, 30, 10, VYYY Task 4: deleteNodeAfter Please Enter the node data after which you want to delete a node: 12 Node have been deleted successfully! 50, 12, 20, 40, 30, 10Step 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