Exemple #1
0
        public void Test_Delete_Then_Verify_Properties()
        {
            //     10                  10
            //    /   \               /   \
            //   4     50            4     50
            //  / \   /  \      =>  / \   /  \
            // 3   5 30   65       3   5 30   65
            //      / \   / \           / \   / \ 
            //     20 40 60  70        20 40 60  70
            IBinarySearchTree <byte> bt = this.CreateFullBinaryTree();

            bt.Delete(60);
            bt.Delete(70);

            BT.Node <byte> node = bt.Get(65) !;

            Assert.False(bt.IsEmpty);
            Assert.NotNull(node.Parent);
            Assert.Equal(50, node.Parent !.Value);
            Assert.Null(node.Left !);
            Assert.Null(node.Right !);
        }
Exemple #2
0
        public void Test_Delete_Then_Verify_Properties()
        {
            //       ->30                    40
            //        /  \                  /  \
            //       20   40               20   50
            //      /      \              /      \
            //     10       50    =>     10       60
            //    /          \          /          \
            //   5            60       5            70
            //  /              \      /             /
            // 3               70    3             65
            //  \              /      \
            //   4            65       4
            IBinarySearchTree <byte> bt = this.CreateFullBinaryTree();

            bt.Delete(30);

            BT.Node <byte> node = bt.Get(40) !;

            Assert.Null(node.Parent);
            Assert.Equal(20, node.Left !.Value);
            Assert.Equal(50, node.Right !.Value);
        }
Exemple #3
0
 public virtual void Delete_RootOnly_NotFound()
 {
     Assert.IsFalse(RootOnly.Delete(60));
 }
Exemple #4
0
 public virtual void Delete_RootLeft_NotFound1()
 {
     Assert.IsFalse(RootLeft.Delete(10));
 }
Exemple #5
0
        public virtual void Delete_FiveNodesLeftFull_HasBothChildren()
        {
            Assert.IsTrue(FiveNodesLeftFull.Delete(25));

            Assert.AreEqual <int>(4, FiveNodesLeftFull.Count);
        }
Exemple #6
0
 public virtual void Delete_EmptyTree()
 {
     Assert.IsFalse(Empty.Delete(50));
 }
Exemple #7
0
        public virtual void Delete_FourNodesRightRight_HasParentAndChild()
        {
            Assert.IsTrue(FourNodesRightRight.Delete(75));

            Assert.AreEqual <int>(3, FourNodesRightRight.Count);
        }
Exemple #8
0
        public virtual void Delete_FourNodesRightLeft_End()
        {
            Assert.IsTrue(FourNodesRightLeft.Delete(75));

            Assert.AreEqual <int>(3, FourNodesRightLeft.Count);
        }
Exemple #9
0
        public virtual void Delete_FourNodesLeftRight_Start()
        {
            Assert.IsTrue(FourNodesLeftRight.Delete(25));

            Assert.AreEqual <int>(3, FourNodesLeftRight.Count);
        }
Exemple #10
0
        public virtual void Delete_ThreeNodesFull_Root()
        {
            Assert.IsTrue(ThreeNodesFull.Delete(50));

            Assert.AreEqual <int>(2, ThreeNodesFull.Count);
        }
Exemple #11
0
 public virtual void Delete_RootRight_NotFound1()
 {
     Assert.IsFalse(RootRight.Delete(25));
 }