Exemple #1
0
        public void BatchDelete()
        {
            // The constructed AVL Tree would be
            //     30
            //    /  \ 
            //   20   40
            //  /  \   \ 
            // 10  25   50

            var tree = new AvlTree <int>();

            tree.Insert(10);
            tree.Insert(20);
            tree.Insert(25);
            tree.Insert(30);
            tree.Insert(40);
            tree.Insert(50);
            tree.Insert(60);
            tree.Insert(70);
            tree.Insert(80);
            tree.Insert(90);
            tree.Insert(100);

            var toRemove     = tree.FirstOrderedSubsequence(node => node.Key >= 20 && node.Key < 35);
            var removedCount = tree.BatchDelete(toRemove.Select(node => node.Key));

            Assert.That(removedCount, Is.EqualTo(3));

            tree.TraversalMode = TraversalMode.InOrder;
            var actual = tree;

            CollectionAssert.AreEqual(new[] { 10, 40, 50, 60, 70, 80, 90, 100 }, actual);

            AssertTreeIsBalanced(tree);
        }