check if linked list is circular or not

PHOTO EMBED

Fri Jul 19 2024 06:27:21 GMT+0000 (Coordinated Universal Time)

Saved by @vishnu_jha #c++ #dsa #linkedlist #reverselinkedlist #recursion #circular

// check if a linked list is circular or not
bool isCircular (node* head) {
  if (head == NULL) {
    return true;
  }
  node* temp = head -> next;
  while (temp != NULL && temp != head) {
    temp = temp -> next;
  }
  if (temp == head) {
    return true;
  }
  return false;
}
content_copyCOPY

https://youtu.be/fi2vh0nQLi0?list=PLDzeHZWIZsTryvtXdMr6rPh4IDexB5NIA