Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need help with the second part of this C++ assignment. Here is the assignment: h

ID: 3571200 • Letter: N

Question

Need help with the second part of this C++ assignment.

Here is the assignment: http://docdro.id/7CAjSlg

Explanation / Answer

#include using namespace std; class LinkedList{ // Struct inside the class LinkedList // This is one node which is not needed by the caller. It is just // for internal work. struct Node { int x; Node *next; }; // public member public: // constructor LinkedList(){ head = NULL; // set head to NULL } // This prepends a new value at the beginning of the list void addValue(int val){ Node *n = new Node(); // create new Node n->x = val; // set value n->next = head; // make the node point to the next node. // If the list is empty, this is NULL, so the end of the list --> OK head = n; // last but not least, make the head point at the new node. } // returns the first element in the list and deletes the Node. // caution, no error-checking here! int popValue(){ Node *n = head; int ret = n->x; head = head->next; delete n; return ret; } // private member private: Node *head; // this is the private member variable. It is just a pointer to the first Node }; int main() { LinkedList list; list.addValue(5); list.addValue(10); list.addValue(20); cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote