 |
AppletTalk.com Java discussions newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Guest
|
Posted: Wed Feb 22, 2006 4:12 pm Post subject: Linked list - Infinite loop nodes, how to detect position? H |
|
|
Hi,
I am working on a linked list class, and i have been provided the
reference to the first node. The problem is, if there is a loop in the
nodes, how can i detect the exact position? I know that I can detect a
loop by creating two references, and one of them moving twice the speed
of the first, but that doesn't help in detecting the exact location.
Will appreciate any suggestions/logic/ideas to approach this issue.
Thanks!!
Ali |
|
| Back to top |
|
 |
Oliver Wong Guest
|
Posted: Wed Feb 22, 2006 5:12 pm Post subject: Re: Linked list - Infinite loop nodes, how to detect positio |
|
|
<aliasger.jaffer (AT) gmail (DOT) com> wrote in message
news:1140624682.888849.291730 (AT) o13g2000cwo (DOT) googlegroups.com...
| Quote: | Hi,
I am working on a linked list class, and i have been provided the
reference to the first node. The problem is, if there is a loop in the
nodes, how can i detect the exact position? I know that I can detect a
loop by creating two references, and one of them moving twice the speed
of the first, but that doesn't help in detecting the exact location.
Will appreciate any suggestions/logic/ideas to approach this issue.
|
How about counting how many nodes point to a given node, and if that
value is ever greater than 1, that's where the loop is occuring?
- Oliver |
|
| Back to top |
|
 |
Eric Sosman Guest
|
Posted: Wed Feb 22, 2006 6:12 pm Post subject: Re: Linked list - Infinite loop nodes, how to detect positio |
|
|
aliasger.jaffer (AT) gmail (DOT) com wrote On 02/22/06 11:11,:
| Quote: | Hi,
I am working on a linked list class, and i have been provided the
reference to the first node. The problem is, if there is a loop in the
nodes, how can i detect the exact position? I know that I can detect a
loop by creating two references, and one of them moving twice the speed
of the first, but that doesn't help in detecting the exact location.
|
What do you mean by "the exact location?" Where is
"the exact location" of the loop in (ASCII art alert):
A ---> B
^ |
| |
| v
D <--- C
?
--
Eric.Sosman (AT) sun (DOT) com |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|