Given a pointer to the head of a linked list and a pointer to a node, write a method to remove the node from the given list. bool RemoveNode(Node *&head, Node *n) { if (!head || !n) return false; if (head == n) { head = head->next; n->next = nullptr; //delete n; return true; } Node *curr = head; while (curr->next) { if (n == curr->next) { Node *temp = curr->next; curr->next = curr->next->next; temp->next = nullptr; //delete temp; return true; } curr = curr->next; } return false; } |