Esempio n. 1
0
        private static void AssertResult(string tree, int[] expected)
        {
            var root   = TreeReader.ReadTree(tree);
            var actual = TreeToList(root);

            bool match = true;

            foreach (var i in expected)
            {
                if (actual.Value != i)
                {
                    match = false;
                    break;
                }

                actual = actual.Next;
            }

            if (!match)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"expected: {expected} actual: {actual}");

                Console.ResetColor();
            }
        }
Esempio n. 2
0
        private static string Merge(Node root1, Node root2)
        {
            // convert to sorted array, merge sort, convert back to tree
            var array1      = FlattenTree(root1);
            var array2      = FlattenTree(root2);
            var mergedArray = MergeArrays(array1, array2);
            var root        = BuildTreeFromArray(mergedArray);

            return(TreeReader.WriteTree(root));
        }
Esempio n. 3
0
        private static void Assert(string tree, int expected)
        {
            var root   = TreeReader.ReadTree(tree);
            var actual = FindSecond(root);

            if (actual != expected)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"expected: {expected} actual: {actual}");

                Console.ResetColor();
            }
        }
        private static void AssertResult(string tree, string expected)
        {
            var root   = TreeReader.ReadTree(tree);
            var actual = VerticalTraversal(root);

            if (actual != expected)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"expected: {expected} actual: {actual}");

                Console.ResetColor();
            }
        }
Esempio n. 5
0
        private static void AssertResult(string tree, string[] expected)
        {
            var root   = TreeReader.ReadTree(tree);
            var actual = LevelOrder(root);

            if (actual.Length != expected.Length || !actual.SequenceEqual(expected))
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"expected: {expected} actual: {actual}");

                Console.ResetColor();
            }
        }
        private static void AssertResult(string input, int sum, int expected)
        {
            var root   = TreeReader.ReadTree(input);
            var actual = FindSubtrees(root, sum);

            if (actual != expected)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"expected: {expected} actual: {actual}");

                Console.ResetColor();
            }
        }
Esempio n. 7
0
        private static void AssertResult(string tree1, string tree2, string expected)
        {
            var root1  = TreeReader.ReadTree(tree1);
            var root2  = TreeReader.ReadTree(tree2);
            var actual = Merge(root1, root2);

            if (actual != expected)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine($"expected: {expected} actual: {actual}");

                Console.ResetColor();
            }
        }