本文整理汇总了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();
}
}
示例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");
}
示例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.");
}