Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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);
        }
Esempio 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));
 }
Esempio 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);
        }