Beispiel #1
0
        public void DFSBinarySearchTreeInOrderRecursiveTest()
        {
            var binarySearchTree = new BinarySearchTreeKey();

            binarySearchTree.Add("4");
            binarySearchTree.Add("2");
            binarySearchTree.Add("6");
            binarySearchTree.Add("1");
            binarySearchTree.Add("3");
            binarySearchTree.Add("5");
            binarySearchTree.Add("7");

            Assert.Equal(new [] { "1", "2", "3", "4", "5", "6", "7" }, DFS.DFSBinarySearchTreeInOrderRecursive(binarySearchTree.Root));
        }
Beispiel #2
0
        public void TraverseBinarySearchTreeRecursiveTest()
        {
            var binarySearchTree = new BinarySearchTreeKey();

            binarySearchTree.Add("4");
            binarySearchTree.Add("2");
            binarySearchTree.Add("6");
            binarySearchTree.Add("1");
            binarySearchTree.Add("3");
            binarySearchTree.Add("5");
            binarySearchTree.Add("7");

            Assert.Equal(new [] { "4", "2", "6", "1", "3", "5", "7" }, BFS.TraverseBinarySearchTreeRecursive(binarySearchTree.Root));
        }
Beispiel #3
0
        public void TraverseBinarySearchTreeByLevelRecursive()
        {
            var binarySearchTree = new BinarySearchTreeKey();

            binarySearchTree.Add("4");
            binarySearchTree.Add("2");
            binarySearchTree.Add("6");
            binarySearchTree.Add("1");
            binarySearchTree.Add("3");
            binarySearchTree.Add("5");
            binarySearchTree.Add("7");

            Assert.Equal(new[] { "4", "26", "1357" },
                         BFS.TraverseBinarySearchTreeByLevelRecursive(binarySearchTree.Root).Select(
                             x => x.Aggregate((total, y) => total + y))
                         );
        }
        public void Add()
        {
            var binarySearchTree = new BinarySearchTreeKey();

            binarySearchTree.Add("d");
            binarySearchTree.Add("b");
            binarySearchTree.Add("f");
            binarySearchTree.Add("a");
            binarySearchTree.Add("c");
            binarySearchTree.Add("e");
            binarySearchTree.Add("g");
            binarySearchTree.Remove("e");

            Assert.Equal(true, binarySearchTree.Contains("c"));
            Assert.Equal(false, binarySearchTree.Contains("l"));
            Assert.Equal("a", binarySearchTree.GetMin());
            Assert.Equal("g", binarySearchTree.GetMax());
            Assert.Equal(false, binarySearchTree.Contains("e"));
        }