Sep-06-2022, 06:44 PM
Very new to programming and simply dont understand how this while loop is being used? Is the itr=itr.next the condition that needs to be maintained? I cant find any examples where there isnt a condition with the while statement.
while itr:
llstr += str(itr.data) + '-->'
itr = itr.next
while itr:
llstr += str(itr.data) + '-->'
itr = itr.next
class Node: def __init__(self, data=None, next= None): self.data = data self.next = next class linkedlist: def __init__(self): self.head = None def insert_at_beginning(self, data): node = Node(data, self.head) self.head = node def print(self): if self.head is None: print("Linked List is empty") return itr = self.head llstr = '' while itr: llstr += str(itr.data) + '-->' itr = itr.next print(llstr)