public void LinkedListCycle_HasCycle()
        {
            var list = ListNodeHelpers.CreateCycleLinkedList(new int[4] {
                3, 2, 0, -4
            }, 1);

            HasCycle(list).ShouldBe(true);
            var list_1 = ListNodeHelpers.CreateCycleLinkedList(new int[2] {
                1, 2
            }, 0);

            HasCycle(list_1).ShouldBe(true);
            var list_2 = ListNodeHelpers.CreateCycleLinkedList(new int[1] {
                1
            }, -1);

            HasCycle(list_2).ShouldBe(false);
        }
Esempio n. 2
0
        public void LinkedListCycle_HasCycle()
        {
            var list = ListNodeHelpers.CreateCycleLinkedList(new int[4] {
                3, 2, 0, -4
            }, 1);

            DetectCycle(list).val.ShouldBe(2);
            var list_1 = ListNodeHelpers.CreateCycleLinkedList(new int[2] {
                1, 2
            }, 0);

            DetectCycle(list_1).val.ShouldBe(1);
            var list_2 = ListNodeHelpers.CreateCycleLinkedList(new int[1] {
                1
            }, -1);

            DetectCycle(list_2).ShouldBe(null);
        }