Linked List5
Linked List5
2 2
DOUBLY LINKED LIST
Example for deletion of the last node from a doubly linked list
Algorithm for deletion of the node
whose position is given by the user:
delet_p(dhead,pos)
Step 1. count = 1
Step 2. IF dhead == NULL
Step 3. PRINT “ The linked list is empty”
Step 4. END OF IF
Step 5. ELSE
Step 6. temp = dhead
Step 7. IF pos == 1
Step 8. dhead = ADDRESSNEXT(dhead)
Step 9. IF dhead != NULL
Step 10. ADDRESSPREVIOUS(dhead) = NULL
Step 11. END OF IF
Continue..
Step 12. DEALLOCATE MEMORY FOR temp
Step 13. END OF IF
Step 14. WHILE count < pos AND ADDRESSNEXT(temp)! = NULL
Step 15. temp = ADDRESSNEXT(temp)
Step 16. count = count+1
Step 17. END OF WHILE
Step 18. IF pos == count
Step 19.
ADDRESSNEXT(ADDRESPRVIOUS(temp))=ADDRESSNEXT(temp)
Step 20. ADDRESPRVIOUS(ADDRESSNEXT(temp))
= ADDRESSPREVIOUS(temp)
Continue with Example
Step 21. DEALLOCATE MEMORY FOR temp
Step 22. END OF IF
Step 23. ELSE
Step 24. PRINT “ Wrong input for position”
Step 25. END OF ELSE
Step 26. END OF ELSE
Example for deletion of the 3rd node from a doubly linked list
Traversal of Nodes in
Doubly Linked List
In a doubly linked list the traversal of nodes can be
done sequentially in both directions
• from the first node to the last node and
• from the last node to first node.
Algorithm for traversing
nodes in a doubly linked
list:
traverse(dhead)
Step 1. temp = dhead
Step 2. IF dhead == NULL
Step 3. PRINT “The linked list is empty”
Step 4. ELSE
Step 5. /* Traversal in the forward direction */
Step 6. WHILE temp != NULL
Step 7. temp = ADDRESSNEXT(temp)
Step 8. END OF WHILE
Step 9. /* Traversal in the backward direction */
Step 10. WHILE temp !=NULL
Step 11. temp = ADDRESSPREVIOUS(temp)
Step 12. END OF WHILE
Step 13. END OF ELSE
References
WEB LINKS
• https://www.geeksforgeeks.org/data-structures/
• https://www.javatpoint.com/data-structure-tutoria
l
• https://www.tutorialspoint.com/data_structures_al
gorithms/index.htm
VIDEO LINK
• https://www.youtube.com/watch?v=AT14lCXuMKI
&list=PLdo5W4Nhv31bbKJzrsKfMpo_grxuLl8LU
Research Paper
• https://books.google.co.in/books?id=S-tXjl1hsUYC
THANK YOU
27