當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。