Floyd Algorithm Doubt


where am i gng wrong?

slow = head;

node*prev = fast;

while(fast != NULL){

    prev = fast ;//added line.. this is because when finally the cycling element will be found it will the element where the cycle is formed so u need to keep track of one element before that

    fast = fast->next;

    slow = slow->next;

    //prev->next = fast; this does not update prev this simply loses the pointer to the current fast

    if(fast == slow){

        prev->next = NULL; // u need thus to break the cycle

        break;

    }

}

can you please modify my code and explain so that i could understand better