本文整理汇总了C#中RedBlackTree.FindGreaterThan方法的典型用法代码示例。如果您正苦于以下问题:C# RedBlackTree.FindGreaterThan方法的具体用法?C# RedBlackTree.FindGreaterThan怎么用?C# RedBlackTree.FindGreaterThan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBlackTree
的用法示例。
在下文中一共展示了RedBlackTree.FindGreaterThan方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: run
//.........这里部分代码省略.........
// 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);
}
for (int i = 0; i < k.Length; i++)
k[i] = -1 - k[i]; // undo negation above
// check the localization functions
for (int i = 0; i < k.Length; i++)
{
int kd = (int)(0.01 * (rand.Next() % (k.Length * 150) - k.Length * 25));
var le = t.FindLessThanOrEqualTo(kd);
var gt = t.FindGreaterThan(kd);
var node = t.Min();
double lek = le != null ? le.Value : int.MinValue;
double gtk = gt != null ? gt.Value : int.MaxValue;
if (node.Value > kd)
{
Assert.IsNull(le);
Assert.IsNotNull(gt);
Assert.AreEqual(gt, node);
}
else
{
var succ = node;
do
{
node = succ;
succ = t.GetNextNode(node);
} while (succ != null && succ.Value <= kd);
Assert.AreEqual(node, le);
Assert.AreEqual(succ, gt);
}
}
// Remove elements from the tree
for (int M = k.Length; M > 0; M--)
{
int j = rand.Next() % M;
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 = t.Remove(node);
Assert.IsTrue(t.check());
k[i] = -1 - k[i];
}
// The tree should be empty
Assert.AreEqual(0, t.Count);
}