當前位置: 首頁>>代碼示例>>C#>>正文


C# BinarySearchTree.Minimum方法代碼示例

本文整理匯總了C#中BinarySearchTree.Minimum方法的典型用法代碼示例。如果您正苦於以下問題:C# BinarySearchTree.Minimum方法的具體用法?C# BinarySearchTree.Minimum怎麽用?C# BinarySearchTree.Minimum使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BinarySearchTree的用法示例。


在下文中一共展示了BinarySearchTree.Minimum方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: RunBST

        private static void RunBST()
        {
            var values = new[] { 15, 6, 20, 3, 7, 17, 19, 22, 2, 4, 13, 9 };

            Console.WriteLine($"Building binary tree from: {Utils.FormatArray(values)} =>\n");

            var tree = new BinarySearchTree<int>();
            foreach (var v in values)
            {
                tree.Add(v);
            }

            Utils.PrintBinaryTree(tree.Root);

            Console.WriteLine($"Minimum : {tree.Minimum().Value}");
            Console.WriteLine($"Maximum : {tree.Maximum().Value}");

            var searchValues = new[] { 9, 3, 100, 20, 2 };
            Console.WriteLine($"Searching values {Utils.FormatArray(searchValues)}");
            foreach(var v in searchValues)
            {
                var node = tree.Search(v);
                Console.Write("The tree {0} value {1}. ",
                    node == null ? "does not contain" : "contains", v);

                if (node != null)
                {
                    var successor = BinarySearchTree<int>.Successor(node);
                    Console.Write("Successor {0}. ", successor != null ? successor.Value.ToString() : "N/A");
                    var predecessor = BinarySearchTree<int>.Predecessor(node);
                    Console.Write("Predecessor {0}.", predecessor != null ? predecessor.Value.ToString() : "N/A");
                }

                Console.WriteLine();
            }

            var deleteValues = new [] { 15 };
            foreach (var v in deleteValues)
            {
                var node = tree.Search(v);
                Console.WriteLine($"Deleting value: {v}");
                tree.Delete(node);
                Utils.PrintBinaryTree(tree.Root);
                Console.WriteLine();
            }
        }
開發者ID:moozzyk,項目名稱:AlgorithmsInCSharp,代碼行數:46,代碼來源:BinarySearchTreeRunner.cs

示例2: MaximumMinimum

        public void MaximumMinimum()
        {
            var tree = new BinarySearchTree<MockComparable>();
            var mock = new MockComparable(3);
            var node = new TNode<MockComparable>(mock);
            tree.Insert(node);

            Assert.AreEqual(3, tree.Maximum().Content.Value, "#AA01");
            Assert.AreEqual(3, tree.Minimum().Content.Value, "#AA01bis");

            var mock2 = new MockComparable(7);
            var node2 = new TNode<MockComparable>(mock2);
            tree.Insert(node2);
            Assert.AreEqual(7, tree.Maximum().Content.Value, "#AA02");
            Assert.AreEqual(3, tree.Minimum().Content.Value, "#AA02bis");
        }
開發者ID:bpatra,項目名稱:sandbox,代碼行數:16,代碼來源:BinarySearchTreeTests.cs

示例3: TreeMinimumTest

 public void TreeMinimumTest()
 {
     BinarySearchTree target = new BinarySearchTree(); // TODO: Initialize to an appropriate value
     BinarySearchTree.Node x = null; // TODO: Initialize to an appropriate value
     BinarySearchTree.Node expected = null; // TODO: Initialize to an appropriate value
     BinarySearchTree.Node actual;
     actual = target.Minimum(x);
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
開發者ID:jamesjrg,項目名稱:taipan,代碼行數:10,代碼來源:BinarySearchTreeTest.cs


注:本文中的BinarySearchTree.Minimum方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。