Question: Using C++, create a singly linked list having 5 nodes when instantiated. Create the following methods for your linked list: 1) InsertBeginning(): This function will
Using C++, create a singly linked list having 5 nodes when instantiated. Create the following methods for your linked list:
1) InsertBeginning(): This function will accept a value from the user, which will be used to create a new node at the beginning of the linked list.
2) InsertEnd(): This function will accept a value from the user, which will be used to create a new node at the end of the linked list.
3) Insert(): This function will accept a value and a location from the user, and will then add a node with the provided value in the location specified by the user.
4) DeleteBeginning(): This function will delete the first node of the linked list.
5) DeleteEnd(): This function will delete the last node of the linked list.
6) Delete(): This function will take a user input specifying which node to delete.
7) View(): This function will display the linked list.
This program should be menu driven, and once it is run, it will first display the initial linked list, and then ask the user for his/her option. Something like the following:
1.insert beginning node
2.insert last node
3.insert node at position
4.Delete first node
5.Delete last node
6.Delete node at specific location
7.Exit
The options will be the functions you are going to implement. The menu should be in a loop and will only end, if the user presses the option to terminate the program.
After each operation is performed, the resulting linked list will be displayed to the user, before asking for his/her option again.
Remember to consider every possible outcome of the program, and handle it accordingly.
Please include a SinglyLinkedList.hpp, SinglyLinkedList.cpp, and main.cpp.
I'm using Xcode for this. Please display code from the compiler and the output. Thank you!
ATTACHED IS A WAY TO DO THE MAIN FUNCTION or something similar of how it should be written.
int user_choice; basic_linked_list bll; NULL; head-node while (1) = cout > user choice switch (user choice) case 1: bll.InsertBeginning bll.View( case 2: bll.InsertEnd) bll.View( case 3: bll.Insert) bll.View( break; case 4: bll.DeleteBeginning); bll.View( case 5: bll.DeleteEnd) bll.View( break; case 6: bll.Deletel) bll.View() case 7: cout
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
