Tuesday, May 22, 2012

Deletion of the node in link list

When Key found (current node is ptr)

next: ptr->next
previous: ptr->prev
previous's next: (ptr->prev)->next
next's previous (ptr->next)->prev


  • Create connection 

If the key is head,
1. set head to the next
2. set next's previous to null

If key is tail
1. set tail to the previous
2. set previous's next to null

If key is in the middle
1. set previous's next to next
2. set next's previous to previous


  • Disconnect the current node 

1. set current's next to null
2. set current's previous to null


  • Delete current node 

free(ptr);

No comments:

Post a Comment