当前位置: 首页>>代码示例>>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;未经允许,请勿转载。