Java program to insert a new node at the end of the Doubly Linked ListIn this program, we will create a doubly linked list and insert every new node at the end of the list. If the list is empty, then head and tail will point to newly added node. If list is not empty then, insert the new node at the end of the list such that tail's next will point to new node. Make new node as new tail of the list and its next will point to null. In above example, node 4 was the tail of the list. Now, the new node will be inserted at the end of the list such that node 4's next will point to new node. Make new node as the tail of the list, and its next will point to null. Algorithm
a. display() will show all the nodes present in the list.
Program:Output: Adding a node to the end of the list: 1 Adding a node to the end of the list: 1 2 Adding a node to the end of the list: 1 2 3 Adding a node to the end of the list: 1 2 3 4 Adding a node to the end of the list: 1 2 3 4 5 Next TopicJava Programs |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India