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);
};

SAMPLE SOLUTION bool LinkedList::remove(string s) { // find the matching node node *target = front; while ((target != NULL) && (target->s != s)) target = target->next; // if no such node was found, return failure if (target == NULL) return false; // identify the nodes before/after it node *before = target->prev; node *after = target->next; // remove the targetted node if (after) after->prev = before; else back = before; if (before) before->next = after; else front = after; // delete the node and return success delete target; return true; }