Question: Delete the last node of the Linked List //Delete last node of the list void pop_back() {// Check if there is LL if(head != NULL)
Delete the last node of the Linked List
//Delete last node of the list void pop_back() {// Check if there is LL if(head != NULL) {// if only one node if(head->next == NULL) { head = NULL;} // more than one nodeelse { Node* temp = head; while(temp->next->next != NULL){ temp = temp->next;} temp->next = NULL; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
