Question
How to add nodes to the beginning, end and middle of a doubly linked list?
1. Illustration and Steps
1.1. Add nodes to the beginning of the doubly linked list
Illustration (GeeksforGeeks, 2022):
Steps:
1 | //Step1: newNode->next set to head |
1.2. Add nodes to the end of the doubly linked list
Illustration (GeeksforGeeks, 2022):
Steps:
1 | //Step1: tail->next set to newNode |
1.3. Add nodes in between the doubly linked list
Illustration (GeeksforGeeks, 2022):
Steps:
1 | //Step1: newNode->next set to preNode.next |
2. Program
2.1. Codes
1 | /** |
2.2. Outputs
1 | Add nodes at the end of the linked list: |
Word count: 738
References
1.GeeksforGeeks. (2022). Doubly Linked List | Set 1 (Introduction and Insertion).
https://www.geeksforgeeks.org/doubly-linked-list/
2.SoftwareTestingHelp. (2022). Doubly Linked List In Java – Implementation & Code Examples.
https://www.softwaretestinghelp.com/doubly-linked-list-in-java/