We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
You can simply increment a counter variable by 1 every time you do "head=head.next". if the counter goes beyond 100, the list has a loop. If the loop ends before that, it doesn't
Linked Lists: Detect a Cycle
You are viewing a single comment's thread. Return to all comments →
You can simply increment a counter variable by 1 every time you do "head=head.next". if the counter goes beyond 100, the list has a loop. If the loop ends before that, it doesn't