Question 4. A linked list remove method [6]
Given the definition below for a linked list class (where the constructor initializes front and back to NULL, and inserts always go at the front of the list), provide an appropriate implemention for the remove method.
class LinkedList { private: // internally the list is a chain of nodes struct node { string s; node *next, *prev; }; // maintain pointers to the front and back nodes node *front, *back; public: LinkedList(); // initializes the empty list ~LinkedList(); // deallocates remaining list nodes void print(); // prints the list from front to back // create and insert at front of list, // returning true iff successful bool insert(string s); // find and remove the node with the specified string, // returning true iff successful bool remove(string s); }; |