Example #1
0
        public static void Test()
        {
            ListNode head = new ListNode(1);

            head.Next                     = new ListNode(2);
            head.Next.Next                = new ListNode(3);
            head.Next.Next.Next           = new ListNode(4);
            head.Next.Next.Next.Next      = new ListNode(5);
            head.Next.Next.Next.Next.Next = new ListNode(6);

            head.Next.Next.Next.Next.Next.Next = head.Next.Next;
            Print(LinkedListCycleStart.FindCycleStart(head));

            head.Next.Next.Next.Next.Next.Next = head.Next.Next.Next;
            Print(LinkedListCycleStart.FindCycleStart(head));

            head.Next.Next.Next.Next.Next.Next = head;
            Print(LinkedListCycleStart.FindCycleStart(head));
        }
Example #2
0
 private static void Print(ListNode node)
 {
     Console.WriteLine($"LinkedList cycle start: {LinkedListCycleStart.FindCycleStart(node).Value}");
 }