Advertisement
Guest User

Untitled

a guest
Dec 22nd, 2013
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. First, eliminate the pathological case of a 3-element list with a cycle from element 2 to 1. Keep two
  2. pointers. One at element 1 and the next at element 3. See if they are equal; if not, move P1 by one and
  3. P2 by two. Check and continue. If P1 or P2 is null, there is no loop. If there is one, it will definitely be
  4. detected. One pointer will eventually catch up with the other (i.e., have the same value), though it
  5. might take several traversals of the cycle to do it.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement