character strings are stored in the three linked lists inn fig.....(a) find the three strings. (b) form circular header lists from the one-way lists using CHAR[20],CHAR[19] and CHAR[18] as header nodes
class Node:
def __init__(self, d):
self.d = d
self.next = None
class circular_linked_list:
def __init__(self):
self.hd = None
def push(self, d):
p1 = Node(d)
temp = self.hd
p1.next = self.hd
if self.hd is not None:
while(temp.next != self.hd):
temp = temp.next
temp.next = p1
else:
p1.next = p1
self.hd = p1
def display(self):
temp = self.hd
if self.hd is not None:
while(True):
print (temp.d, end=" ")
temp = temp.next
if (temp == self.hd):
break
c = circular_linked_list()
c.push(1)
c.push(2)
c.push(3)
c.push(4)
c.display()
Comments
Leave a comment