forked from mayankchaudhary26/HacktoberFest-Practice-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremoval_ofduplicates_incircular_linkedlist.py
More file actions
65 lines (61 loc) Β· 1.74 KB
/
removal_ofduplicates_incircular_linkedlist.py
File metadata and controls
65 lines (61 loc) Β· 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
class Node:
def __init__(self,data):
self.data = data
self.next = None
class list_creation:
def __init__(self):
self.head = Node(None)
self.tail = Node(None)
self.head.next = self.tail
self.tail.next = self.head
def add_data(self,my_data):
new_node = Node(my_data)
if self.head.data is None:
self.head = new_node
self.tail = new_node
new_node.next = self.head
else:
self.tail.next = new_node
self.tail = new_node
self.tail.next = self.head
def remove_duplicate_vals(self):
curr = self.head
if(self.head == None):
print("The list is empty")
else:
while(True):
temp = curr
index_val = curr.next
while(index_val != self.head):
if(curr.data == index_val.data):
temp.next = index_val.next
else:
temp = index_val
index_val= index_val.next
curr =curr.next
if(curr.next == self.head):
break;
def print_it(self):
curr = self.head
if self.head is None:
print("The list is empty");
return;
else:
print(curr.data)
while(curr.next != self.head):
curr = curr.next
print(curr.data)
print("\n")
class circular_linked_list:
my_cl = list_creation()
print("Nodes are being added to the list")
my_cl.add_data(21)
my_cl.add_data(54)
my_cl.add_data(78)
my_cl.add_data(99)
my_cl.add_data(21)
print("The list is :")
my_cl.print_it();
my_cl.remove_duplicate_vals()
print("The updated list is :")
my_cl.print_it();