本文整理汇总了C#中BinaryTree.Traverse方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryTree.Traverse方法的具体用法?C# BinaryTree.Traverse怎么用?C# BinaryTree.Traverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinaryTree
的用法示例。
在下文中一共展示了BinaryTree.Traverse方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TreeSort
/// <summary>
/// Tree sort
/// Performance:
/// worst-case:
/// unbalanced O(n^2)
/// balanced O(n log n)
/// average: O(n log n)
/// best: O(n)
/// Space complexity: need to build a new tree with key and two leafs. So, it is 3N
/// </summary>
/// <param name='array'>Array for sorting</param>
public void TreeSort(int[] array)
{
if (array == null || array.Length < 2) return;
BinaryTree<int> root = new BinaryTree<int>(array[0]);
for (int i = 1; i < array.Length; ++i)
root.Insert(new BinaryTree<int>(array[i]));
var enumerator = root.Traverse().GetEnumerator();
for (int i = 0; i < array.Length && enumerator.MoveNext(); ++i)
array[i] = enumerator.Current;
}
示例2: PrepareScript
private BinaryTree<Script> PrepareScript(BinaryTree<Script> script)
{
if (script == null)
return null;
var visitors = new Collection<IVisitor>
{
new PathCompilerVisitor(Contact),
new QuestionCompilerVisitor(Contact, Telesale, LeadPerson)
};
script.Traverse(new PreOrderTravel(), visitors);
return script;
}