top of page

Add Operation - Doubly Linked List

  • Writer: Tirthankar Pal
    Tirthankar Pal
  • Mar 8, 2022
  • 1 min read

If we want to insert a new node cur after an existing node prev, we can divide this process into two steps:

  1. link cur with prev and next, where next is the original next node of prev

ree

re-link the prev and next with cur.


ree

Similar to the singly linked list, both the time and the space complexity of the add operation are O(1).


An Example


ree

Let's add a new node 9 after the existing node 6:

  1. link cur (node 9) with prev (node 6) and next (node 15)

ree

re-link prev (node 6) and next (node 15) with cur (node 9)


ree

 
 
 

Comments


bottom of page