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

Popular posts from this blog

How whatsapp works

ABOUT WHATSAPP

Edit Java Class file at runtime