![]() |
VOOZH | about |
Given a doubly linked list, the task is to delete the node from the beginning of the linked list.
Examples:
Input : 1 <-> 2 <-> 3 -> NULL
Output : 2 <-> 3 <-> NULLInput : 2 <-> 4 <-> 6 <-> 8 <-> 33 <-> 67 <-> NULL
Output : 4 <-> 6 <-> 8 <-> 33 <-> 67 <-> NULL
Approach:
The idea is to update the head of the doubly linked list to the node next to head node and if the new head is not NULL, then set the previous pointer of new head to NULL.
To delete a node at the beginning in doubly linked list, we can use the following steps:
Original Linked List: 1 2 3 After Deletion at the beginning: 2 3
Time Complexity: O(1)
Auxiliary Space: O(1)