Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 15th, 2012  |  syntax: None  |  size: 0.82 KB  |  hits: 14  |  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. Finding the junction node in a linklist having a loop in it [closed]
  2. head -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
  3.                   ^                        |
  4.                   |                        |
  5.                   +------------------------+
  6.        
  7. A   B
  8. =   =
  9. 1   2
  10. 2   4
  11. 3   6
  12. 4   8
  13. 5   4
  14. 6   6
  15.        
  16. (C goes this way).
  17.         C ->>                    A (this is where A and B
  18.         |                        |              first met).
  19.         v                        v
  20. head -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
  21.                   ^                        |
  22.                   |                        |
  23.                   +------------------------+
  24.                    (B runs through this loop, every time
  25.                     it reaches A, you advance C; when it
  26.                     reaches C, that's your first loop node).