Ejemplo n.º 1
0
        /// <summary>
        /// Probs the 2 6 is palindrome.
        /// Implement a function to check if a linked list is a Palindrome
        /// </summary>
        public static void Prob_2_6_IsPalindrome_Test()
        {
            var inputText = "tacocat";

            //var inputText = "tacoocat";
            //var inputText = "bobo";
            Console.WriteLine($"Checking if {inputText} is a palindrome");
            var input = LinkedNode <char> .CreateNodeFromString(inputText);

            var output = Prob_2_6_IsPalindrome_v2(input);


            Console.WriteLine($"Expected result: " + true);
            Console.WriteLine($"Actual output: {output}");
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Prob2s the 2 delete middle node test.
        /// Implement an algorithm to delete a node in the middle (i.e. any node
        /// but the first and last node, not necessarely the exact middle) of a
        /// singly linked list WHEN GIVEN only access to THAT node. Example:
        ///
        /// Input: The node C (from the linked list a->b->c->d->e->f
        /// Result: Nothing is returned but the new linked list looks like: a->b->d->e->f
        ///
        /// </summary>
        public static void Prob_2_3_DeleteMiddleNode_test()
        {
            var input = LinkedNode <char> .CreateNodeFromString("abcdef");

            Console.WriteLine("Input before changes:");
            input.PrintValues();

            var nodeToRemove = input.GetFirstNodeWithValue('c');

            Console.WriteLine($"Vallue to remove {nodeToRemove.data}");
            Prob_2_3_DeleteMiddleNode_v1(nodeToRemove);

            Console.WriteLine("Input AFTER changes:");
            input.PrintValues();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Probs the 2 7 integration test.
        /// Given two singly linked. Determine if the two
        /// lists intersect. Return the intersection node.
        /// Note: The intersection is defined based on reference
        /// , not value. That is, if the kth node of the first
        /// linked list is the exact same node (by reference) as
        /// the jth node of the second list, then they are intersecting
        /// </summary>
        public static void Prob_2_7_Intesection_Test()
        {
            var firstList = LinkedNode <char> .CreateNodeFromString("hello world");

            var secondList = firstList.GetNodeXPositionsFromCurrent(3);
            var otherList  = LinkedNode <char> .CreateNodeFromString("hello world");

            var result = Prob_2_7_DoListsIntersect_v1(firstList, otherList);

            Console.WriteLine("Expected Results: TRUE");
            Console.WriteLine($"Actual result: {result != null}");
            if (result != null)
            {
                Console.WriteLine($"Intersecting node: {result.data}");
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Prob2s the 2 return kth to the last test.
        /// Implement an algorith to find the kth to the last element
        /// og a silgly linked list
        /// </summary>
        public static void Prob_2_2_ReturnKthToTheLast_Test()
        {
            var inputString = "123456789";
            var input       = LinkedNode <char> .CreateNodeFromString(inputString);

            var kthToLastElementNum = 7;
            ///var expectedOutput = '7';

            //var kthToLastNode = Prob2_2_ReturnKthToTheLast(input, kthToLastElementNum);
            var kthToLastNode = Prob_2_2_ReturnKthToTheLast_v2(input, kthToLastElementNum);


            Console.WriteLine("Input: ");
            input.PrintValues();

            Console.WriteLine($"{kthToLastElementNum} to last element is {inputString[(inputString.Length -1) - kthToLastElementNum]}");
            Console.WriteLine($"Actual output: {kthToLastNode.data}");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Probs the 2 1 remove dups test.
        /// Write code to remove duplicates from an unsorted list
        /// </summary>
        public static void Prob_2_1_RemoveDups_Test()
        {
            var testInput = LinkedNode <char> .CreateNodeFromString("FOLLOW UP");

            Console.WriteLine($"Input:");
            testInput.PrintValues();

            var expectedOutput = LinkedNode <char> .CreateNodeFromString("FOLW UP");

            Console.WriteLine($"Expected results:");
            expectedOutput.PrintValues();

            //var output = Pro2_1_RemoveDupsv1(testInput);
            var output = Pro_2_1_RemoveDupsv1(testInput);


            Console.WriteLine($"Actual results:");
            output.PrintValues();
        }