Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Complete the code from the constructor part onwards using c++ for the Singly Linked List class file1 (1).txt Edited N 1 N N 4 N

image text in transcribedComplete the code from the constructor part onwards using c++ for the Singly Linked List class

image text in transcribedimage text in transcribedimage text in transcribed

file1 (1).txt Edited N 1 N N 4 N 9 45 35 20 11 57 36 28 94 73 55 34 #include #include #include #include using namespace std; class Node { private: int elem; //data element Node* next; //Link (pointer) to the next Node public: Node(int elem): elem(elem), next(NULL) 1 friend class MyLinkedList; }; class MyLinkedList { private: Node* head; // pointer to the head of list public: MyLinkedList (); // empty list constructor -MyLinkedList(); // destructor to clean up all nodes bool empty const; // is list empty? const int& front) const; // get the element/data from the front Node void addFront(const int& elem); // add a new Node at the front of the list void removeFront(); // remove front Node from the list void display() const; void loadData(string); //read a file and load it into the linked list void dumpData(string) const; // write the linked list to a file I/Optional Task void sort(); // sort the elements of the list }; void listCommands { cout : Add to the front of the Linked List" : Load the data from and add it into the Linked List" : Dump the contents of the Linked list to ""; getline(cin,user_input); command = user_input.substr(0,user_input.find("")); parameter = user_input.substr(user_input.find("")+1); if(command=="display") myList.displayO; else if(command=="addFront" or command="add") myList.addFront(stoi parameter)),myList.display(); else if(command--"removeFront" or command--"remove") myList.removeFront(),myList.display(); else if(command=="load") myList.loadData(parameter),myList.display(); else if(command == "dump") myList.dumpData(parameter); else if(command == "sort") myList.sort,myList.displayO; else if(command == "help") listCommands; else if(command == "exit") break; else couthead = NULL; } ====== // destructor to clean up all nodes MyLinkedList::-MyLinkedList { // } // Check if the list is empty or not bool MyLinkedList::empty0 const { // } // return the value/elemnt at the front of the lsit const int& MyLinkedList::front() const { // } Il add a node at the front of list void MyLinkedList::addFront(const int& elem) { // } // remove the first node from the list void MyLinkedList::removeFront) { //=== // display all nodes of the linked list void MyLinkedList::display() const { // } IT I/Load data from a file and add it to the Linked List void MyLinkedList::loadData(string path) { I/ } //Dump/write the contents of the list to a file void MyLinkedList::dumpData(string path) const { // } Il // sort the elments of the list using: Hint use bubble_sort void MyLinkedList::sort) { // } file1 (1).txt Edited N 1 N N 4 N 9 45 35 20 11 57 36 28 94 73 55 34 #include #include #include #include using namespace std; class Node { private: int elem; //data element Node* next; //Link (pointer) to the next Node public: Node(int elem): elem(elem), next(NULL) 1 friend class MyLinkedList; }; class MyLinkedList { private: Node* head; // pointer to the head of list public: MyLinkedList (); // empty list constructor -MyLinkedList(); // destructor to clean up all nodes bool empty const; // is list empty? const int& front) const; // get the element/data from the front Node void addFront(const int& elem); // add a new Node at the front of the list void removeFront(); // remove front Node from the list void display() const; void loadData(string); //read a file and load it into the linked list void dumpData(string) const; // write the linked list to a file I/Optional Task void sort(); // sort the elements of the list }; void listCommands { cout : Add to the front of the Linked List" : Load the data from and add it into the Linked List" : Dump the contents of the Linked list to ""; getline(cin,user_input); command = user_input.substr(0,user_input.find("")); parameter = user_input.substr(user_input.find("")+1); if(command=="display") myList.displayO; else if(command=="addFront" or command="add") myList.addFront(stoi parameter)),myList.display(); else if(command--"removeFront" or command--"remove") myList.removeFront(),myList.display(); else if(command=="load") myList.loadData(parameter),myList.display(); else if(command == "dump") myList.dumpData(parameter); else if(command == "sort") myList.sort,myList.displayO; else if(command == "help") listCommands; else if(command == "exit") break; else couthead = NULL; } ====== // destructor to clean up all nodes MyLinkedList::-MyLinkedList { // } // Check if the list is empty or not bool MyLinkedList::empty0 const { // } // return the value/elemnt at the front of the lsit const int& MyLinkedList::front() const { // } Il add a node at the front of list void MyLinkedList::addFront(const int& elem) { // } // remove the first node from the list void MyLinkedList::removeFront) { //=== // display all nodes of the linked list void MyLinkedList::display() const { // } IT I/Load data from a file and add it to the Linked List void MyLinkedList::loadData(string path) { I/ } //Dump/write the contents of the list to a file void MyLinkedList::dumpData(string path) const { // } Il // sort the elments of the list using: Hint use bubble_sort void MyLinkedList::sort) { // }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

More Books

Students also viewed these Databases questions

Question

2. Describe why we form relationships

Answered: 1 week ago

Question

5. Outline the predictable stages of most relationships

Answered: 1 week ago