Finding loop in a singly linked-list
You can detect it by simply running two pointers through the list, this process is known as the tortoise and hare algorithm after the fable of the same name: First off, check if the list is empty (head is null). If so, no cycle exists, so stop now. Otherwise, start the first pointer tortoise on … Read more