13. Python program to remove duplicate elements from a Doubly Linked List.In this program, we will create a doubly linked list and remove the duplicate, if present, by traversing through the list. List after removing duplicates: In the above list, node2 is repeated thrice, and node 3 is repeated twice. Current will point to head, and index will point to node next to current. Start traversing the list till a duplicate is found that is when current's data is equal to index's data. In the above example, the first duplicate will be found at position 4. Assign index to another node temp. Connect index's previous node with index's next node. Delete temp which was pointing to duplicate node. This process will continue till all duplicates are removed. ALGORITHM:
a. removeDuplicateNode() will remove duplicate nodes from the list.
a. display() will show all the nodes present in the list.
PROGRAM:Output: Originals list: 1 2 3 2 2 4 5 3 List after removing duplicates: 1 2 3 4 5 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