![]() |
VOOZH | about |
Given a doubly linked list, the task is to delete the last node of the given linked list.
Examples:
Input: 1 <-> 2 <-> 3 <-> NULL
Output: 1 <-> 2 <-> NULL
Explanation: The last node of the linked list is 3, so 3 is deleted.Input: 15 -> NULL
Output: NULL
Explanation: The last node of the linked list is 15, so 15 is deleted.
Approach:
To perform the deletion operation at the end of doubly linked list, we need to traverse the list to find thesecond last node, then set its next pointer tonull.
To delete a node at the end in doubly linked list, we can use the following steps:
Original Linked List: 1 2 3 After Deletion at the end: 1 2
Time Complexity: O(N), where N is the number of nodes in the linked list
Auxiliary Space: O(1)