10. Python program to insert a new node at the beginning of the Doubly Linked list.In this program, we will create a doubly linked list and insert every new node at the beginning of the list. If the list is empty, then head and tail will point to the newly added node. If the list is not empty then, insert the new node at the beginning of the list such that the head's previous will point to the new node. Make new node as head of the list, and its previous will point to null. Consider the above example. Initially, 1 was the head of the list. Now new will be inserted before node 1 such that node 1's previous will point to new. Make new as the head of the list, and its previous will point to null ALGORITHM:
a. display() will show all the nodes present in the list.
PROGRAM:Output: Adding a node to the start of the list: 1 Adding a node to the start of the list: 2 1 Adding a node to the start of the list: 3 2 1 Adding a node to the start of the list: 4 3 2 1 Adding a node to the start of the list: 5 4 3 2 1 Next TopicPython 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