** Pastebin PRO Accounts Easter Special ** Get 40% discount for a limited time only! Click Here to check it out ;-)Want more features on Pastebin? Sign Up, it's FREE!


By: a guest on Dec 22nd, 2013  |  syntax: None  |  size: 0.47 KB  |  views: 46  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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.
clone this paste RAW Paste Data