Пример #1
0
        public void GetHeightOfTreeTest()
        {
            // crate a tree
            TreeNode <int> root = new TreeNode <int>(3);

            TreesAndGraphs.Insert(root, 2);
            TreesAndGraphs.Insert(root, 1);
            TreesAndGraphs.Insert(root, 5);
            TreesAndGraphs.Insert(root, 4);
            TreesAndGraphs.Insert(root, 6);
            TreesAndGraphs.Insert(root, 7);
            var height = TreesAndGraphs.GetHeightOfTree(root);

            Assert.AreEqual(3, height);

            root = new TreeNode <int>(3);
            TreesAndGraphs.Insert(root, 2);
            TreesAndGraphs.Insert(root, 1);
            TreesAndGraphs.Insert(root, 5);
            TreesAndGraphs.Insert(root, 4);
            TreesAndGraphs.Insert(root, 6);
            TreesAndGraphs.Insert(root, 7);
            TreesAndGraphs.Insert(root, 8);
            TreesAndGraphs.Insert(root, 20);
            TreesAndGraphs.Insert(root, 19);
            TreesAndGraphs.Insert(root, 18);
            TreesAndGraphs.Insert(root, 16);
            TreesAndGraphs.Insert(root, 15);
            TreesAndGraphs.Insert(root, 17);
            height = TreesAndGraphs.GetHeightOfTree(root);
            Assert.AreEqual(9, height);
        }
Пример #2
0
        public void TesIfABinaryTreeIsBalancedOrNot()
        {
            // create a new tree sructure
            TreeNode <int> root = new TreeNode <int>(3);

            TreesAndGraphs.Insert(root, 2);
            TreesAndGraphs.Insert(root, 1);
            TreesAndGraphs.Insert(root, 3);
            TreesAndGraphs.Insert(root, 5);
            TreesAndGraphs.Insert(root, 4);
            TreesAndGraphs.Insert(root, 6);
            List <LinkedList <TreeNode <int> > > list = new List <LinkedList <TreeNode <int> > >();
            var output = TreesAndGraphs.IsBalanced(root);
        }
Пример #3
0
        public void CreateLevelLinkedList()
        {
            // create a new tree sructure
            TreeNode <int> root = new TreeNode <int>(3);

            TreesAndGraphs.Insert(root, 2);
            TreesAndGraphs.Insert(root, 1);
            TreesAndGraphs.Insert(root, 3);
            TreesAndGraphs.Insert(root, 5);
            TreesAndGraphs.Insert(root, 4);
            TreesAndGraphs.Insert(root, 6);
            List <LinkedList <TreeNode <int> > > list = new List <LinkedList <TreeNode <int> > >();

            TreesAndGraphs.CreateLevelLinkedList(root, list, 0);

            // View the content of the list to see the linkedlist structure
        }