本文整理汇总了C#中RedBlackTree.Min方法的典型用法代码示例。如果您正苦于以下问题:C# RedBlackTree.Min方法的具体用法?C# RedBlackTree.Min怎么用?C# RedBlackTree.Min使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBlackTree
的用法示例。
在下文中一共展示了RedBlackTree.Min方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: run
private static void run(int n)
{
var rand = Accord.Math.Tools.Random;
RedBlackTree<int> t = new RedBlackTree<int>(allowDuplicates: true);
// Create a vector of random numbers
int[] k = new int[n];
for (int i = 0; i < k.Length; i++)
k[i] = rand.Next(k.Length);
int[] sorted = (int[])k.Clone();
Array.Sort(sorted);
// Populate the tree with numbers
for (int i = 0; i < k.Length; i++)
{
var node = t.Add(k[i]);
Assert.IsNotNull(node);
Assert.AreEqual(k[i], node.Value);
Assert.IsTrue(t.check());
}
Assert.AreEqual(k.Length, t.Count);
// Check that all elements are in the tree
for (int i = 0; i < k.Length; ++i)
{
var node = t.Find(k[i]);
Assert.IsNotNull(node);
Assert.AreEqual(k[i], node.Value);
Assert.IsTrue(t.Contains(k[i]));
Assert.IsTrue(t.Contains(node));
}
// Enumerate the values (must be in order)
int arrayIndex = 0;
foreach (var node in t)
Assert.AreEqual(sorted[arrayIndex++], node.Value);
// Start from min and go navigating up to max
var min = t.Min();
Assert.IsNotNull(min);
Assert.AreEqual(k.Min(), min.Value);
for (int i = 0; i < k.Length; i++)
{
Assert.IsNotNull(min);
min = t.GetNextNode(min);
}
Assert.IsNull(min); // the last should be null.
// Start from max and go navigating down to min
var max = t.Max();
Assert.AreEqual(k.Max(), max.Value);
for (int i = 0; i < k.Length; i++)
{
Assert.IsNotNull(max);
max = t.GetPreviousNode(max);
}
Assert.IsNull(max); // the last should be null.
// Exercise the tree
for (int M = k.Length; M > 0; M--)
{
int knew = rand.Next(k.Length); // random new key
int j = rand.Next(M); // random original key to replace
int i;
for (i = 0; i < k.Length; i++)
if (k[i] >= 0)
if (j-- == 0)
break;
if (i >= k.Length)
Assert.Fail();
int kd = k[i];
var node = t.Find(kd);
Assert.IsNotNull(node);
node.Value = knew;
Assert.IsNotNull(t.Resort(node));
Assert.IsTrue(t.check());
k[i] = -1 - knew;
Assert.AreEqual(k.Length, t.Count);
}
//.........这里部分代码省略.........
示例2: RBT_MinMax
public void RBT_MinMax()
{
var RBT = new RedBlackTree<int, object>();
RBT[4] = 0; RBT[3] = 0; RBT[2] = 0; RBT[1] = 0;
RBT[5] = 0; RBT[6] = 0; RBT[7] = 0;
Assert.AreEqual(1, RBT.Min().Item1);
Assert.AreEqual(7, RBT.Max().Item1);
}