So this is my code to detect loop. I have a doubt here. Why am I looking for current in dic instead of current.data in dic.? Its giving wrong answer if I store that value of the node alone. What happens when I store the value of the node instead of the Node. I am learning linked list, SO I am unable to grasp what happens when I store the Node itself and what happens when I store the value of Node alone.
def detectLoop(head):
dic={}
current=head
flag=5
while current is not None:
if current in dic:
flag=6
break
else:
dic[current]=5
current=current.next
if flag==5:
return False
else:
return True