remove loop from linked list

PHOTO EMBED

Fri Jul 19 2024 12:19:25 GMT+0000 (Coordinated Universal Time)

Saved by @vishnu_jha ##c++ ##dsa ##linkedlist ##circular ##loop #floyd'sloopdetection ##algorithm

void removeLoop(node *head) {
  if (head == NULL) {
    return;
  }
  node *startOfLoop = getStartingNode(head);
  node *temp = startOfLoop;
  while (temp->next != startOfLoop) {
    temp = temp->next;
  }
  temp->next = NULL;
  cout << "loop is removed " << endl;
}
content_copyCOPY

point the last node to NULL