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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment