Example #1
0
        public void TestRemove()
        {
            var tree = new RBTree <int>();

            for (var i = 0; i < 500; i++)
            {
                tree.InsertSuccessor(RBTree <int> .GetLast(tree.Root), i);
                for (var j = 0; j <= i; j++)
                {
                    var traverse = RBTree <int> .GetFirst(tree.Root);

                    for (var k = 0; k < j; k++)
                    {
                        traverse = traverse.Next;
                    }
                    //remove jth element
                    tree.RemoveNode(traverse);
                    var check = RBTree <int> .GetFirst(tree.Root);

                    for (var k = 0; k < j; k++)
                    {
                        Assert.AreEqual(k, check.Data);
                        check = check.Next;
                    }
                    for (var k = j; k < i; k++)
                    {
                        Assert.AreEqual(k + 1, check.Data);
                        check = check.Next;
                    }
                    //readd
                    tree.InsertSuccessor(traverse.Previous, traverse.Data);
                }
            }
        }