cycle detection in list
int HasCycle(Node* head)
{
// Complete this function
// Do not write the main method
Node * fast = head;
Node * slow = head;
while(fast!=NULL && slow!=NULL && fast->next)
{
fast=fast->next->next;
slow=slow->next;
if(fast==slow)
{
return 1;
}
}
return 0;
}
Comments
Post a Comment