algorithm - Circular list detection in Python? -
is there way observe first element of circular list in python? in java , c++ can found pointer first element.
question came across: given circular linked list, implement algorithm returns node @ origin of loop.
a circular linked list has no true origin & end. comment, think want observe when reach element started while looping through list.
#the construction of listnode class listnode: def __init__(self, val): self.val = val self.next = none # supposes have circular linked list , have reference head. can follows print whole list. current = head.next while current != head: # stop when comes head print current.val current = current.next
python algorithm linked-list circular-list
No comments:
Post a Comment