public void AddNode(int d)
Node new_node = new Node(d);
Console.Write("{0}->,", tnode.data);
while (fast != null && fast.next != null)
if (slow.next.data == fast.next.data)
while (fast != null && fast.next != null)
if (slow.next.data == fast.next.data)
public void Printloop(int key)
Console.WriteLine("No loop");
Console.WriteLine("Loop detected at {0},", key);
public static void Main()
Program p = new Program();
int[] list = new int[]{1, 2, 3, 4, 5};
for (int i = 0; i < list.Length; i++)
p.head.next.next.next.next.next = p.head.next.next;
int key = p.Detectloop();
int keys = p.Detectloop();