Write a program to implement a doubly linked list
A doubly Linked List is a variation to a normal Linked List where, instead of one pointer pointing to the next node, there are 2 pointers, one pointing to the next node and the other one to the previous node.
Source: Geeks4Geeks
- A DLL can be traversed in both forward and backward direction.
- The delete operation in DLL is more efficient if pointer to the node to be deleted is given.
- We can quickly insert a new node before a given node.
In singly linked list, to delete a node, pointer to the previous node is needed. To get this previous node, sometimes the list is traversed. In DLL, we can get the previous node using previous pointer.
- Every node of DLL Require extra space for an previous pointer. It is possible to implement DLL with single pointer though (See this and this).
- All operations require an extra pointer previous to be maintained. For example, in insertion, we need to modify previous pointers together with next pointers. For example in following functions for insertions at different positions, we need 1 or 2 extra steps to set previous pointer.
Try to implement a doubly linked list.
// To Be Added