Data Abstraction & Problem Solving with C++ Ch. 9 Exercise 2 Define the method replace for the class LinkedList. This is all the question states. C++ language, a partial pseudocode is acceptable, as there's no way to make a whole program with the given information.
C++ CODE:
class LinkedList{ private: struct Node{ int data; Node *next; }; Node *head; public: LinkedList() : head(nullptr) {} void replace(int replaceThis, int withThis); }; void LinkedList::replace(int replaceThis, int withThis){ for(Node *ptr = head; ptr != nullptr; ptr = ptr->next){ if(ptr->data == replaceThis){ ptr->data = withThis; return; } } cout << replaceThis << " not found in the list\n"; }
IF YOU NEED ANY HELP THEN JUST LET ME KNOW IN THE COMMENTS
Get Answers For Free
Most questions answered within 1 hours.