当前位置: 首页>>代码示例>>C#>>正文


C# BinarySearchTree.Clear方法代码示例

本文整理汇总了C#中BinarySearchTree.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# BinarySearchTree.Clear方法的具体用法?C# BinarySearchTree.Clear怎么用?C# BinarySearchTree.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinarySearchTree的用法示例。


在下文中一共展示了BinarySearchTree.Clear方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Simple

        public void Simple()
        {
            var tree = new BinarySearchTree<int, string>();
            tree.Clear();

            Assert.AreEqual(tree.Count, 0);

            tree = GetTestTree();
            Assert.IsTrue(tree.ContainsKey(19));

            tree.Clear();
            Assert.AreEqual(tree.Count, 0);
            Assert.IsFalse(tree.ContainsKey(19));
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:14,代码来源:Clear.cs

示例2: ClearTest

 public void ClearTest(string[] elements)
 {
     BinarySearchTree<string> bst = new BinarySearchTree<string>(elements);
     bst.Clear();
     PexAssert.IsNull(bst.Root);
     PexAssert.AreEqual(0, bst.Count);
 }
开发者ID:taoxiease,项目名称:asegrp,代码行数:7,代码来源:BinarySearchTreeTest.cs

示例3: ClearTest

        public void ClearTest()
        {
            BinarySearchTree<int> bst = new BinarySearchTree<int> {10, 5, 15};

            bst.Clear();

            Assert.IsNull(bst.Root);
            Assert.AreEqual(0, bst.Count);
        }
开发者ID:taoxiease,项目名称:asegrp,代码行数:9,代码来源:BinarySearchTreeTest.cs

示例4: Simple

        public void Simple()
        {
            var tree = new BinarySearchTree<int, string>();
            Assert.IsTrue(tree.IsEmpty);

            tree = GetTestTree();
            Assert.IsFalse(tree.IsEmpty);

            tree.Clear();
            Assert.IsTrue(tree.IsEmpty);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:11,代码来源:IsEmpty.cs

示例5: Main

        static void Main(string[] args)
        {
            const int itemsCount = 10000;

            // Adding consecutive items
            Console.Write("Adding {0} consecutive items: ", itemsCount);
            var tree = new BinarySearchTree<int>(Enumerable.Range(0, itemsCount));
            if (tree.Count == itemsCount)
                Console.WriteLine("Success!");
            else
                Console.WriteLine("Failed!");
            Console.WriteLine();

            // Clearing tree
            Console.Write("Clearing the tree: ");
            tree.Clear();
            if (tree.Count == 0)
                Console.WriteLine("Success!");
            else
                Console.WriteLine("Failed!");
            Console.WriteLine();

            // Adding random numbers
            Console.Write("Adding {0} random numbers: ", itemsCount);
            var random = new Random();
            var numbersAdded = new List<int>();
            for (int i = 0; i < itemsCount; i++)
            {
                try
                {
                    int number = random.Next(0, 99999999);
                    tree.Add(number);
                    numbersAdded.Add(number);
                }
                catch { }
            }
            var diff = numbersAdded.Except(tree);
            if (diff.Count() == 0)
                Console.WriteLine("Success!");
            else
                Console.WriteLine("Failed!");
            Console.WriteLine();

            // Deleting
            int item = tree.ElementAt(500);
            Console.Write("Deleting item {0}: ", item);
            tree.Remove(item);
            if (tree.Contains(item))
                Console.WriteLine("Failed!");
            else
                Console.WriteLine("Success!");

            int item2 = tree.ElementAt(300);
            Console.Write("Deleting item {0}: ", item2);
            tree.Remove(item2);
            if (tree.Contains(item2))
                Console.WriteLine("Failed!");
            else
                Console.WriteLine("Success!");

            int item3 = tree.ElementAt(600);
            Console.Write("Deleting item {0}: ", item3);
            tree.Remove(item3);
            if (tree.Contains(item3))
                Console.WriteLine("Failed!");
            else
                Console.WriteLine("Success!");

            int item4 = tree.ElementAt(463);
            Console.Write("Deleting item {0}: ", item4);
            tree.Remove(item4);
            if (tree.Contains(item4))
                Console.WriteLine("Failed!");
            else
                Console.WriteLine("Success!");
            Console.WriteLine();

            // Check the count now
            Console.Write("Check for consistency: ");
            var diff1 = numbersAdded
                .Where(x => x != item && x != item2 && x != item3 && x != item4)
                .Except(tree);
            if (diff1.Count() > 0)
                Console.WriteLine("Failed!");
            else
                Console.WriteLine("Success!");
            Console.WriteLine();

            // Clone
            Console.Write("Cloning tree: ");
            var clone = (BinarySearchTree<int>)tree.Clone();
            if (clone.Count == tree.Count && !Object.ReferenceEquals(clone, tree))
                Console.WriteLine("Success!");
            else
                Console.WriteLine("Failed!");

            Console.ReadLine();
        }
开发者ID:nok32,项目名称:SoftUny-HW,代码行数:98,代码来源:Program.cs

示例6: ClearTest

 public void ClearTest()
 {
     var bst = new BinarySearchTree<int>() { 10, 15, 5, 4, 7, 20, 14, 0, -5, -8, -2, -1 };
     bst.Clear();
     Assert.AreEqual(0, bst.Count, "Clearing the bst did not work");
 }
开发者ID:jojojojochen,项目名称:Algorithm-Implementations,代码行数:6,代码来源:BinarySearchTreeTests.cs

示例7: ClearExample

        public void ClearExample()
        {
            // Create a simple tree
            BinarySearchTreeBase<string, int> tree = new BinarySearchTree<string, int>
                                                         {
                                                             new KeyValuePair<string, int>("cat", 1),
                                                             new KeyValuePair<string, int>("dog", 2),
                                                             new KeyValuePair<string, int>("canary", 3)
                                                         };

            // There should be 3 items in the tree.
            Assert.AreEqual(3, tree.Count);

            // Clear the tree
            tree.Clear();

            // The tree should be empty.
            Assert.AreEqual(0, tree.Count);

            // No cat here..
            Assert.IsFalse(tree.ContainsKey("cat"));
        }
开发者ID:havok,项目名称:ngenerics,代码行数:22,代码来源:BinarySearchTreeBaseExamples.cs

示例8: IsEmptyExample

        public void IsEmptyExample()
        {
            BinarySearchTreeBase<string, int> tree = new BinarySearchTree<string, int>();

            // Tree is empty.
            Assert.IsTrue(tree.IsEmpty);

            // Add a cat.
            tree.Add(new KeyValuePair<string, int>("cat", 1));

            // Tree is not empty.
            Assert.IsFalse(tree.IsEmpty);

            // Clear the tree - thereby removing all items contained.
            tree.Clear();

            // Tree is empty again with count = 0.
            Assert.IsTrue(tree.IsEmpty);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:19,代码来源:BinarySearchTreeBaseExamples.cs

示例9: CountExample

        public void CountExample()
        {
            BinarySearchTreeBase<string, int> tree = new BinarySearchTree<string, int>();

            // Tree count is 0.
            Assert.AreEqual(0, tree.Count);

            // Add a cat.
            tree.Add(new KeyValuePair<string, int>("cat", 1));

            // Tree count is 1.
            Assert.AreEqual(1, tree.Count);

            // Add a dog
            tree.Add(new KeyValuePair<string, int>("dog", 2));

            // Tree count is 2.
            Assert.AreEqual(2, tree.Count);

            // Clear the tree - thereby removing all items contained.
            tree.Clear();

            // Tree is empty again with 0 count.
            Assert.AreEqual(0, tree.Count);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:25,代码来源:BinarySearchTreeBaseExamples.cs

示例10: TestClear

        public void TestClear()
        {
            var tree = new BinarySearchTree<int>();
            var size = 10;
            for (int i = 0; i < size; i++)
            {
                tree.Add(i);
            }

            tree.Clear();
            Assert.AreEqual(tree.Count, 0);
            Assert.IsTrue(tree.IsEmpty);
        }
开发者ID:deva666,项目名称:BinarySearchTree,代码行数:13,代码来源:BinaryTreeTests.cs


注:本文中的BinarySearchTree.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。