コード例 #1
0
        static void Main(string[] args)
        {
            LinkedList cyclicList = new LinkedList();

            cyclicList.Insert(6);
            cyclicList.Insert(5);
            cyclicList.Insert(4);
            cyclicList.Insert(3);
            cyclicList.Insert(2);
            cyclicList.Insert(1);
            cyclicList.MakeCyclic(3);

            var isCyclic = CyclicLinkedList.IsCyclic(cyclicList);

            Console.WriteLine($"Is the List Cyclic: {isCyclic}");

            Console.WriteLine();

            var cyclicLength = CyclicLinkedList.FindCyclicLLLength(cyclicList.Head);

            Console.WriteLine($"Cycle Length: {cyclicLength}");

            var educativeCycleLength = CyclicLinkedList.FindCycleLength(cyclicList.Head);

            Console.WriteLine($"Educative Cycle Length: {educativeCycleLength}");

            Console.WriteLine();

            var start = CyclicLinkedList.FindCycleStart(cyclicList.Head);

            Console.WriteLine($"Start of the list: {start.Value}");

            Console.WriteLine();

            var educativeStart = LinkedListStart.FindCycleStart(cyclicList.Head);

            Console.WriteLine($"Starting Node (Educative): {educativeStart.Value}");

            Console.WriteLine();

            var happyNumber = HappyNumber.IsHappyNumber(23);

            Console.WriteLine($"Is number happy? {happyNumber}");

            Console.WriteLine();

            var fastSlowHappyNumber = HappyNumber.IsHappyNumberFastSlow(1234);

            Console.WriteLine($"Is number happy (Fast/Slow)? {fastSlowHappyNumber}");

            Console.WriteLine();

            LinkedList ll = new LinkedList();

            ll.Insert(6);
            ll.Insert(5);
            ll.Insert(4);
            ll.Insert(3);
            ll.Insert(2);
            ll.Insert(1);

            var middle = MiddleNode.FindMiddleNode(ll.Head);

            Console.WriteLine($"The middle node is: {middle.Value}");

            Console.WriteLine();

            LinkedList palList = new LinkedList();

            palList.Insert(2);
            palList.Insert(4);
            palList.Insert(6);
            palList.Insert(4);
            palList.Insert(2);

            bool isPal = PalindromeLinkedList.IsLinkedListAPalindrome(palList.Head);

            Console.WriteLine($"Is the List a Palindrome? {isPal}");

            Console.WriteLine();
        }