How many algo possible???

N

nishit.gupta

finding a loop in a lisked list without modifying it.

1.reverse and check for beginning.
2.take two pointers, keep moving 1st by one and 2nd by two locations,
if they meet loop exists.
3.store addresses in an array.


is their any other possible solution???
 
B

bytebro

finding a loop in a lisked list without modifying it.

1.reverse and check for beginning.
2.take two pointers, keep moving 1st by one and 2nd by two locations,
if they meet loop exists.
3.store addresses in an array.

Option 2 is nearly there.

"Take two pointers. One at element 1 and the next at element 3. See
if they are equal; if not, move P1 by 1 and P2 by 2. Check and
continue. If P1 or P2 is null, there is no loop. If there is one, it
will definitely be detected. One pointer will eventually catch up
with the other (i.e. have the same value), though it might take
several traversals of the cycle to do it."

Courtesy of Peter van der Linden's excellent _Expert C Programming:
Deep C Secrets_
 
E

Eric Sosman

finding a loop in a lisked list without modifying it.

1.reverse and check for beginning.
2.take two pointers, keep moving 1st by one and 2nd by two locations,
if they meet loop exists.
3.store addresses in an array.


is their any other possible solution???

Do you have a question about C?

<off-topic>

The answer to the question you asked is "Yes."

</off-topic>
 
N

nishit.gupta

Do you have a question about C?

<off-topic>

The answer to the question you asked is "Yes."

</off-topic>

Ya obviously bro...nywazz how does it matter whether c/c++
algo for detecting loop wud be same in both c n c++
 
C

CBFalconer

Ya obviously bro...nywazz how does it matter whether c/c++
algo for detecting loop wud be same in both c n c++

PLONK for boorishness, use of foolish abbreviations, c++ in a c
newsgroup, and general idiocy. I will not be annoyed further by
your existence.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>
<http://www.aaxnet.com/editor/edit043.html>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top