Esempio n. 1
0
        public void BuildFromInOrderAndPostOrder(int[] inOrder, int[] postOrder)
        {
            var tb = new BinTreeFromPostAndInOrder();

            var root          = tb.BuildTree(inOrder, postOrder);
            var treeTraverser = new BinaryTreeTraversal <int>();

            Assert.Equal(inOrder, treeTraverser.InOrderTraversal(root));
        }
Esempio n. 2
0
        public void Basic()
        {
            var node1 = new TreeNode(1);
            var node2 = new TreeNode(2);
            var node3 = new TreeNode(3);

            node1.right = node2;
            node2.left  = node3;

            var traverser   = new BinaryTreeTraversal <int>();
            var inorderList = traverser.InOrderTraversal(node1);

            Assert.Equal(new [] { 1, 3, 2 }, inorderList);
        }
Esempio n. 3
0
        public void Left_chain()
        {
            var node1 = new TreeNode(1);
            var node2 = new TreeNode(2);
            var node3 = new TreeNode(3);

            node2.left = node1;
            node3.left = node2;

            var traverser   = new BinaryTreeTraversal <int>();
            var inorderList = traverser.InOrderTraversal(node3);

            Assert.Equal(new[] { 1, 2, 3 }, inorderList);
        }