Hi all, I have a doubt regarding finding a loop in a linked list.I searched on internet and found 2 different ways of doing the same. But my doubt is that if a linked list has a loop, then wouldn't it be a circular linked list? If yes, then the loop can be found by testing each node's address field with NULL. Am I right? Awaiting a response.

But my doubt is that if a linked list has a loop, then wouldn't it be a circular linked list?

Not necessarily. This is a circular linked list:

a -> b -> c -> d -+
^                 |
|                 |
+-----------------+

This is a list with a loop, but it's not a circular linked list because the last node doesn't link back to the first node, it links to a node somewhere in the middle:

a -> b -> c -> d -+
          ^       |
          |       |
          +-------+

If yes, then the loop can be found by testing each node's address field with NULL.

How do you know when to stop looking? That's the point of the question.

This question has already been answered. Start a new discussion instead.