
Untitled
By: a guest on
Jul 15th, 2012 | syntax:
None | size: 0.82 KB | hits: 14 | expires: Never
Finding the junction node in a linklist having a loop in it [closed]
head -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
^ |
| |
+------------------------+
A B
= =
1 2
2 4
3 6
4 8
5 4
6 6
(C goes this way).
C ->> A (this is where A and B
| | first met).
v v
head -> 1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8
^ |
| |
+------------------------+
(B runs through this loop, every time
it reaches A, you advance C; when it
reaches C, that's your first loop node).