Answer to Question #259696 in Python for JUNG

Question #259696

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


1
Expert's answer
2021-11-01T18:50:35-0400


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()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog