Find or detect loop in linked list

PHOTO EMBED

Wed Jun 08 2022 20:48:28 GMT+0000 (Coordinated Universal Time)

Saved by @Ranjan_kumar #c++

int findLoop (Node *head)
{
Node *slow, *fast;
slow=head;
fast=head;
 while (fast!=NULL && fast->next!=NULL )
 {
 fast= fast->next->next;
 slow = slow->next;
  if (slow ==  fast)
  {
  return 1;   //loop found
  }
 }
return 0;      //No loop, reached end of list
content_copyCOPY