Beispiel #1
0
        public void Delete_From_InternalNode_BorrowTheGreatestLowerBoundCausesHalfLeafToBeEmpty()
        {
            var tree = new TTree <int>(3, 3);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);

            tree.Add(4);
            tree.Add(5);
            tree.Add(6);

            tree.Add(16);
            tree.Add(17);
            tree.Add(18);

            tree.Add(1);
            tree.Add(2);
            tree.Add(3);

            tree.Remove(4);
            tree.Remove(5);
            tree.Remove(10);

            CheckTree <int>(tree.RootNode, 1, new[] { 6, 11, 12 }, true, true, null, 6);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 1, 2, 3 }, false, false, tree.RootNode, 6);
            CheckTree <int>(tree.RootNode.Right, 0, new[] { 16, 17, 18 }, false, false, tree.RootNode, 6);
        }
Beispiel #2
0
        private void m_deleteButton_Click(object sender, EventArgs e)
        {
            m_root.Remove(int.Parse(m_valueTextBox.Text));
            Redraw();

            ActiveControl = m_valueTextBox;
            m_valueTextBox.SelectAll();
        }
Beispiel #3
0
        public void Delete_From_Leaf_RemovesItem()
        {
            var tree = new TTree <int>(3, 3);

            tree.Add(10);
            tree.Add(5);
            tree.Add(15);

            tree.Remove(10);

            CheckTree <int>(tree.RootNode, 0, new[] { 5, 15 }, false, false, null, 5);
        }
Beispiel #4
0
        public void Delete_From_HalfLeaf_Merges()
        {
            var tree = new TTree <int>(3, 3);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);
            tree.Add(5);

            tree.Remove(12);

            CheckTree <int>(tree.RootNode, 0, new[] { 5, 10, 11 }, false, false, null, 5);
        }
Beispiel #5
0
        public void Delete_From_InternalNode_BorrowTheGreatestLowerBound_WhenLeafBecomesEmpty()
        {
            var tree = new TTree <int>(3, 3);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);
            tree.Add(4);
            tree.Add(15);

            tree.Remove(11);

            CheckTree <int>(tree.RootNode, 1, new[] { 4, 10, 12 }, false, true, null, 4);
            CheckTree <int>(tree.RootNode.Right, 0, new[] { 15 }, false, false, tree.RootNode, 4);
        }
Beispiel #6
0
        public void Delete_From_HalfLeaf_RemovesItem()
        {
            var tree = new TTree <int>(3, 3);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);
            tree.Add(4);
            tree.Add(5);

            tree.Remove(12);

            CheckTree <int>(tree.RootNode, 1, new[] { 10, 11 }, true, false, null, 10);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 4, 5 }, false, false, tree.RootNode, 10);
        }
Beispiel #7
0
        public void Delete_From_NodeNoUnderflow_RemovesItem()
        {
            var tree = new TTree <int>(2, 3);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);
            tree.Add(4);
            tree.Add(5);

            tree.Remove(11);

            CheckTree <int>(tree.RootNode, 1, new[] { 10, 12 }, true, false, null, 10);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 4, 5 }, false, false, tree.RootNode, 10);
        }
Beispiel #8
0
        public void Delete_From_RightLeaf_BecomesEmpty()
        {
            var tree = new TTree <int>(2, 3);

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

            tree.Remove(7);

            CheckTree <int>(tree.RootNode, 1, new[] { 4, 5, 6 }, true, false, null, 4);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 1, 2, 3 }, false, false, tree.RootNode, 4);
        }
Beispiel #9
0
        public void Delete_From_InternalNode_BorrowTheGreatestLowerBound()
        {
            var tree = new TTree <int>(3, 3);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);
            tree.Add(4);
            tree.Add(5);
            tree.Add(15);

            tree.Remove(11);

            CheckTree <int>(tree.RootNode, 1, new[] { 5, 10, 12 }, true, true, null, 5);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 4 }, false, false, tree.RootNode, 5);
            CheckTree <int>(tree.RootNode.Right, 0, new[] { 15 }, false, false, tree.RootNode, 5);
        }
Beispiel #10
0
        public void Delete_ShouldRebalance()
        {
            var tree = new TTree <int>(2, 3);

            tree.Add(10);
            tree.Add(11);
            tree.Add(12);
            tree.Add(1);
            tree.Add(13);
            tree.Add(14);
            tree.Add(15);
            tree.Add(16);

            tree.Remove(1);

            CheckTree <int>(tree.RootNode, 1, new[] { 13, 14, 15 }, true, true, null, 13);
            CheckTree <int>(tree.RootNode.Left, 0, new[] { 10, 11, 12 }, false, false, tree.RootNode, 13);
            CheckTree <int>(tree.RootNode.Right, 0, new[] { 16 }, false, false, tree.RootNode, 13);
        }