Dec 25, 2008

Given the head pointer of a link list, how do you detect a cycle in the

Given the head pointer of a link list, how do you detect a cycle in the
link list efficiently?

using to pointer p and q.
p forwards one element each step.
q forwards two elements each step.
If p equal to q in any step, then there is a cycle.

No comments:

Post a Comment