本文整理汇总了C#中BinarySearchTree.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# BinarySearchTree.GetEnumerator方法的具体用法?C# BinarySearchTree.GetEnumerator怎么用?C# BinarySearchTree.GetEnumerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinarySearchTree
的用法示例。
在下文中一共展示了BinarySearchTree.GetEnumerator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NonIComparable
public void NonIComparable()
{
var tree = new BinarySearchTree<NonComparableTClass, string>
{
{new NonComparableTClass(4), "4"},
{new NonComparableTClass(6), "6"},
{new NonComparableTClass(2), "2"},
{new NonComparableTClass(5), "5"},
{new NonComparableTClass(19), "19"},
{new NonComparableTClass(1), "1"}
};
var newTree = SerializeUtil.BinarySerializeDeserialize(tree);
Assert.AreNotSame(tree, newTree);
Assert.AreEqual(tree.Count, newTree.Count);
var treeEnumerator = tree.GetEnumerator();
var newTreeEnumerator = newTree.GetEnumerator();
while (treeEnumerator.MoveNext())
{
Assert.IsTrue(newTreeEnumerator.MoveNext());
Assert.AreEqual(treeEnumerator.Current.Key.Number, newTreeEnumerator.Current.Key.Number);
Assert.AreEqual(treeEnumerator.Current.Value, newTreeEnumerator.Current.Value);
Assert.IsTrue(newTree.ContainsKey(treeEnumerator.Current.Key));
Assert.AreEqual(newTree[treeEnumerator.Current.Key], treeEnumerator.Current.Value);
}
Assert.IsFalse(newTreeEnumerator.MoveNext());
}
示例2: Enumerate
public void Enumerate()
{
var tree = new BinarySearchTree<int>() { -1, 0, 1 };
var itr = tree.GetEnumerator();
var actual = new List<int>();
while (itr.MoveNext())
actual.Add(itr.Current);
CollectionAssert.AreEquivalent(new int[] { -1, 0, 1 }, actual);
}
示例3: InsertTest
public void InsertTest([PexAssumeUnderTest]int[] newElements)
{
BinarySearchTree<int> bst = new BinarySearchTree<int>(newElements);
PexAssert.AreEqual(newElements.Length, bst.Count);
PexAssert.IsNotNull(bst.GetEnumerator());
PexAssert.IsNotNull(bst.GetPostorderEnumerator());
PexAssert.IsNotNull(bst.GetInorderEnumerator());
PexAssert.IsNotNull(bst.GetBreadthFirstEnumerator());
PexObserve.ValueForViewing<int[]>("newElements", newElements);
PexObserve.ValueForViewing<int[]>("Constructed tree", bst.ToArray());
}
示例4: GetEnumeratorGenericTest
public void GetEnumeratorGenericTest()
{
BinarySearchTree<int> bst = new BinarySearchTree<int> {10, 5, 3, 8, 12, 11};
Assert.IsNotNull(bst.GetEnumerator());
}
示例5: GetEnumeratorExample
public void GetEnumeratorExample()
{
BinarySearchTreeBase<string, int> tree = new BinarySearchTree<string, int>
{
new KeyValuePair<string, int>("cat", 1),
new KeyValuePair<string, int>("dog", 2),
new KeyValuePair<string, int>("canary", 3)
};
var enumerator = tree.GetEnumerator();
// Enumerate through the items in the tree, and write the contents
// to the standard output.
while (enumerator.MoveNext())
{
Console.Write("Key : ");
Console.WriteLine(enumerator.Current.Key);
Console.Write("Value : ");
Console.WriteLine(enumerator.Current.Value);
}
}