I am not looking you to explain the problem with coding... but just let me know what is the problem of cycle detection in linked lists. I read many docs (wikipedia etc.) I cannot understand
I am not looking you to explain the problem with coding... but just let me know what is the problem of cycle detection in linked lists. I read many docs (wikipedia etc.) I cannot understand
The problem is: "Is there a cycle"? Normally when you think of linked lists, you think of a chain. You start at one end, you follow links forward through the chain, and then you reach the end of the chain so you have a NULL link at the end.
If you've managed to somehow tie your linked list into a knot, then (say) object #10, instead of pointing to #11 like it should, is pointing instead to #4. So then you have a loop (or a cycle), and if you follow the links you'll just go around and around forever.
node *fast = head;
node *slow = head;
fast = fast->next;
fast = fast->next;
slow = slow->next;
if ( fast == slow ) you have a loop.
Not forgetting to stop at NULL if you get to the end first.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.