Exemplo n.º 1
0
        public void RightIsNull_StillBst()
        {
            var node0  = new BstNode(5);
            var node01 = new BstNode(4);

            node0.Left = node01;
            Assert.That(IsBst(node0), Is.True);
        }
Exemplo n.º 2
0
        public void RightIsNull_NotBst()
        {
            var node0  = new BstNode(5);
            var node01 = new BstNode(6);

            node0.Left = node01;
            Assert.That(IsBst(node0), Is.False);
        }
Exemplo n.º 3
0
        public void LeftIsNull_NotBst()
        {
            var node0  = new BstNode(5);
            var node02 = new BstNode(4);

            node0.Right = node02;
            Assert.That(IsBst(node0), Is.False);
        }
Exemplo n.º 4
0
        public void LeftIsNull_StillBst()
        {
            var node0  = new BstNode(5);
            var node02 = new BstNode(6);

            node0.Right = node02;
            Assert.That(IsBst(node0), Is.True);
        }
Exemplo n.º 5
0
        public void Repeating()
        {
            var node0  = new BstNode(5);
            var node01 = new BstNode(5);
            var node02 = new BstNode(6);

            node0.Left  = node01;
            node0.Right = node02;
            Assert.That(IsBst(node0), Is.False);
        }
Exemplo n.º 6
0
        public void DeepWrong()
        {
            var node0   = new BstNode(5);
            var node02  = new BstNode(6);
            var node001 = new BstNode(4);

            node0.Right = node02;
            node02.Left = node001;
            Assert.That(IsBst(node0), Is.False);
        }
Exemplo n.º 7
0
        public void ItIsBst()
        {
            var node0  = new BstNode(5);
            var node01 = new BstNode(4);
            var node02 = new BstNode(6);

            node0.Left  = node01;
            node0.Right = node02;

            Assert.That(IsBst(node0), Is.True);
        }
Exemplo n.º 8
0
 public bool IsBst(BstNode root, int min = int.MinValue, int max = int.MaxValue)
 {
     if (root == null)
     {
         return(true);
     }
     return((root.Left == null || (root.Left.Data < root.Data && root.Left.Data > min)) &&
            (root.Right == null || (root.Right.Data > root.Data && root.Right.Data < max)) &&
            IsBst(root.Left, min, root.Data) &&
            IsBst(root.Right, root.Data, max));
 }
Exemplo n.º 9
0
        public void DeepDuplicate()
        {
            var node0    = new BstNode(50);
            var node01   = new BstNode(40);
            var node002  = new BstNode(45);
            var node0002 = new BstNode(50);


            node0.Left    = node01;
            node01.Right  = node002;
            node002.Right = node0002;
            Assert.That(IsBst(node0), Is.False);
        }