AppletTalk.com Forum Index AppletTalk.com
Java discussions newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Linked list - Infinite loop nodes, how to detect position? H

 
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help
View previous topic :: View next topic  
Author Message
Guest






PostPosted: Wed Feb 22, 2006 4:12 pm    Post subject: Linked list - Infinite loop nodes, how to detect position? H Reply with 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.

Thanks!!

Ali
Back to top
Oliver Wong
Guest





PostPosted: Wed Feb 22, 2006 5:12 pm    Post subject: Re: Linked list - Infinite loop nodes, how to detect positio Reply with quote



<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





PostPosted: Wed Feb 22, 2006 6:12 pm    Post subject: Re: Linked list - Infinite loop nodes, how to detect positio Reply with quote



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
Display posts from previous:   
Post new topic   Reply to topic    AppletTalk.com Forum Index -> Java Help All times are GMT
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.