Hide Index
- Understanding insertion at beginning
- Insert at beginning
- Understanding insertion at end
- Insert at end
- Understanding insertion after the given node
- Insert after the given node
- Understanding insertion before a given node
- Insert before the given node
- Understanding insertion at a given distance
- Insert at given distance
- Understanding deletion of first node
- Delete first node
- Understanding deletion of last node
- Delete last node
- Understanding deletion by given data
- Delete node with given data
- Delete nodes with given data
- Understanding deletion after a given node
- Delete node after the given node
- Understanding deletion before a given node
- Delete node before the given node
- Understanding deletion of the given node
- Delete the given node
- Understanding deletion at a given distance
- Delete node at given distance
Understanding insertion at beginning
Inserting a node at the beginning of a doubly linked list is similar to inserting a node at the beginning of a singly linked list. The main difference is that a doubly linked list has two references stored in a node, and we need to keep track of both references. Let's examine the scenarios we need to take into account.
1. The list is empty
In this scenario, if the linked list is empty, the head will be null. We need to initialize the head node of the linked list and ensure that the next and previous pointers of this newly created head node are null, as this node is also the tail node of the list.
Liking the course? Check our discounted plans to continue learning.