How can you find if a given linked list has a cycle in it?
Note: Linked list is singly linked list (there is only next pointer no previous pointer).
See Solution: Detect if there is a cycle in the linked list
Code in C
bool isCyclePresent(Node* node){ Node* pointer1 = node; Node* pointer2 = node; while(pointer2 != null && pointer2->next!=null){ pointer1 = pointer1->next; pointer2 = pointer2->next->next; if(pointer1 == pointer2) return true; } return false; }