本文整理汇总了C#中BinarySearchTree.TryGetNode方法的典型用法代码示例。如果您正苦于以下问题:C# BinarySearchTree.TryGetNode方法的具体用法?C# BinarySearchTree.TryGetNode怎么用?C# BinarySearchTree.TryGetNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinarySearchTree
的用法示例。
在下文中一共展示了BinarySearchTree.TryGetNode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestGetPredecessor
public void TestGetPredecessor()
{
var tree = new BinarySearchTree<int>();
var size = 10;
Node<int> node = null;
for (int i = 0; i < size; i++)
{
node = tree.Add(i);
}
for (int i = size - 1; i >= 0; i--)
{
tree.TryGetNode(i, out node);
var prev = tree.Predecessor(node);
if (i > 0)
Assert.AreEqual(node.Value - 1, prev.Value);
else
Assert.IsNull(prev);
}
}
示例2: TestTryGet
public void TestTryGet()
{
var tree = new BinarySearchTree<int>();
var size = 10;
for (int i = 0; i < size; i++)
{
tree.Add(i);
}
Node<int> node;
for (int i = 0; i < size; i++)
{
Assert.IsTrue(tree.TryGetNode(i, out node));
}
Assert.IsFalse(tree.TryGetNode(1000, out node));
}
示例3: TestGetSuccessor
public void TestGetSuccessor()
{
var tree = new BinarySearchTree<int>();
var size = 10;
Node<int> node = null;
for (int i = 0; i < size; i++)
{
node = tree.Add(i);
}
for (int i = 0; i < size; i++)
{
tree.TryGetNode(i, out node);
var next = tree.Successor(node);
if (i < size - 1)
Assert.AreEqual(node.Value + 1, next.Value);
else
Assert.IsNull(next);
}
}
示例4: TestDelete
public void TestDelete()
{
var tree = new BinarySearchTree<int>();
var size = 10;
for (int i = 0; i < size; i++)
{
tree.Add(i);
}
Assert.AreEqual(tree.Count, size);
Node<int> node;
for (int i = 0; i < size; i++)
{
tree.TryGetNode(i, out node);
tree.Remove(node);
}
Assert.AreEqual(tree.Count, 0);
Assert.IsTrue(tree.IsEmpty);
}