0

Answered # Loop in a linked list!

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.

Narue 5,707 I am wondering if there would be any chance that someone could help me out with this, I am trying to teach myself c++ which i find it really interesting and I came accross this and would love to see how it works so i could do it and learn ...

0

0

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.

Recommended Articles

Hi!

I have two tables, I will call them first-half and second-half (of the year)

```
Table: first
id jan feb mar apr
-----------------------
2 80 90 70 60
3 50 40 60 30
Table: second
id jan feb mar apr
-----------------------
2 50 70 60 90
3 80 60 50 ...
```

```
from turtle import *
import random
def allTriMedian (w=300):
speed (0)
vertices = []
point = turtle.Point(x,y)
for i in range (3):
x = random.randint(0,300)
y = random.randint(0,300)
vertices.append(trutle.Point(x,y))
point = turtle.Point(x,y)
triangle = turtle.Polygon(vertices)
a = triangle.side()
b = triangle.side()
c = triangle.side()
m1 = tirangle.median
m2 = triangle.median ...
```