本文整理汇总了C#中TreeNode.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# TreeNode.GetEnumerator方法的具体用法?C# TreeNode.GetEnumerator怎么用?C# TreeNode.GetEnumerator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeNode
的用法示例。
在下文中一共展示了TreeNode.GetEnumerator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
public static void Main(string[] args)
{
TreeNode a = new TreeNode('a');
TreeNode f = new TreeNode('f');
TreeNode c = new TreeNode(f, null, 'c');
TreeNode d = new TreeNode('d');
TreeNode b = new TreeNode(c, d, 'b');
TreeNode myTree = new TreeNode(a, b, 'e');
for (IEnumerator i = myTree.GetEnumerator(); i.MoveNext();) {
object o = i.Current;
Console.WriteLine(o.ToString());
}
Console.WriteLine("");
// Alternative syntax:
foreach (object o in myTree) {
Console.WriteLine(o.ToString());
}
}
示例2: TestRemoveExistingNodeThatIsNotRoot
public void TestRemoveExistingNodeThatIsNotRoot()
{
var root = new TreeNode<int>(1);
root.Add(2);
root.Add(3);
root.Add(4);
root.Children.ElementAt(0).Add(5);
root.Children.ElementAt(1).Add(6);
root.Children.ElementAt(2).Add(7);
bool removalResult = root.Remove(6);
int[] expected = { 1, 2, 3, 4, 5, 7 };
var bfEnumerator = root.GetEnumerator(VisitType.BreadthFirst);
var elements = new List<int>();
while (bfEnumerator.MoveNext())
{
elements.Add(bfEnumerator.Current);
}
var actual = elements.ToArray();
Assert.IsTrue(removalResult);
Assert.AreEqual(expected.Length, actual.Length);
Assert.AreEqual(expected.Length, root.Count);
for (int i = 0; i < expected.Length; i++)
{
Assert.AreEqual(expected[i], actual[i]);
}
}
示例3: TestTreeBFLimitedTraversal
public void TestTreeBFLimitedTraversal()
{
var root = new TreeNode<int>(4);
var child1 = new TreeNode<int>(5, root);
var child2 = new TreeNode<int>(6, root);
var grandchild1 = new TreeNode<int>(7, child1);
var grandchild2 = new TreeNode<int>(8, child1);
var grandGrandchild1 = new TreeNode<int>(9, grandchild1);
var dfEnumerator = root.GetEnumerator(VisitType.BreadthFirst, 2);
var elements = new List<int>();
var expected = new int[] { 4, 5, 6, 7, 8 };
while (dfEnumerator.MoveNext())
{
elements.Add(dfEnumerator.Current);
}
var actual = elements.ToArray();
Assert.AreEqual(expected.Length, actual.Length);
for (int i = 0; i < expected.Length; i++)
{
Assert.AreEqual(expected[i], actual[i]);
}
}