Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the C++ program below, by adding necessary member functions to the class List. When a main program such as if it runs, the output

Complete the C++ program below, by adding necessary member functions to the class List. When a main program such as if it runs, the output has to be similar to the sample output. In the main program you will work with a list of integers. The whole program should be written in one file ?StudentFullName.cpp? #include using namespace std; //-------------------------------------------------------------------------- //----------------------------- Header ---------------------------------- //-------------------------------------------------------------------------- template class Node { private: T data; Node *next; public: Node(T d, Node* n): data(d), next(n) {} T getData() const {return data;} Node* getNext() const {return next;} void setData(const T &d) {data = d;} void setNext(Node* n) {next = n;} }; template class List{ private: Node *head; public: List(); Node* getHead() const {return head;} void setHead(Node* h) {head = h;} boolisEmpty(); void insertFront(T newData); void deleteFront(); void printList(); int length(); void printBackwards(); void insertEnd(T newData); bool found(T target); void remove(T target); }; //-------------------------------------------------------------------------- //-------------------------- Implementation ------------------------------- //-------------------------------------------------------------------------- template List::List() : head(NULL) {}; template bool List::isEmpty(){ return (head==NULL); } template void List::insertFront(T newData){ Node* node= new Node(newData, head); head=node; } //-------------------------------------------------------------------------- //-------------------------- Client Program ------------------------------ - //-------------------------------------------------------------------------- int main() { //write your main program }

Sample output Operations on Linked lists 1- Insert an element in the front of the list......... 2- delete an element from the

Sample output: Operations on Linked lists... 1- Insert an element in the front of the list.... 2- delete an element from the front of the list.. element at the end of the list. 3- Insert an 4- Search an element in the list... 5- delete an element from the list..... 6- display all elements in the list... 7- display all elements in the list in reverse order. 8- display the length of the list.. 9- Exit the program... Choose an option from the menu: 1 Enter the integer to insert:1 Choose an option from the menu: 1 Enter the integer to insert:2 Choose an option from the menu:1 Enter the integer to insert:3 Choose an option from the menu: 6 List content: [3]--> [2]--> [1] --> Choose an option from the menu:3 Enter an integer to insert at the end:0 Choose an option from the menu: 6 List content: [3]--> [2] --> [1] --> [0] --> Choose an option from the menu: 7 List content backwards: [0]--> [1]--> [2]--> [3]--> Choose an option from the menu:8 length of list = 4 Choose an option from the menu:2 Choose an option from the menu: 6 List content: [2]--> [1]--> [0] --> Choose an option from the menu:5 Enter an integer to remove from the list:2 2 removed from list Choose an option from the menu:6 List content: [1]--> [0]--> Choose an option from the menu:1 Enter the integer to insert: 2 Choose an option from the menu:6 List content: [2] --> [1] --> [0] --> Choose an option from the menu:4 Enter an integer to search in the list:1 We found 1 Choose an option from the menu: 4 Enter an integer to search in the list:8 We did not find 8 Choose an option from the menu:9 End of the program

Step by Step Solution

3.42 Rating (161 Votes )

There are 3 Steps involved in it

Step: 1

include include using namespace std Header template class Node private T data Node next public NodeT ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems analysis and design

Authors: kenneth e. kendall, julie e. kendall

8th Edition

135094909, 013608916X, 9780135094907, 978-0136089162

More Books

Students also viewed these Programming questions

Question

Why are you interested in our program?

Answered: 1 week ago

Question

What are the stages in agile development?

Answered: 1 week ago

Question

What can be shown on a class diagram?

Answered: 1 week ago