While finding the midpoint of a linked list in the video runner technique is being used, so in this technique, if the fast pointer reached null or last pointer then the loop should terminate. In the video the condition for the while is being used is :
void MidPointByRunnerTechnique(node*&head)
{
node* fast=head->next;
node* slow=head;
while((fast!=NULL) && (fast->next!=NULL))
{
fast=fast->next->next;
slow=slow->next;
}
cout<<slow->data<<"\n";
}
why here instead of && , || is not working. Because if either of the two conditions is reached the loop should terminate.
while((fast!=NULL) || (fast->next!=NULL))
{
fast=fast->next->next;
slow=slow->next;
}