本文整理汇总了C#中BinarySearchTree.TraverseToList方法的典型用法代码示例。如果您正苦于以下问题:C# BinarySearchTree.TraverseToList方法的具体用法?C# BinarySearchTree.TraverseToList怎么用?C# BinarySearchTree.TraverseToList使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BinarySearchTree
的用法示例。
在下文中一共展示了BinarySearchTree.TraverseToList方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main()
{
BinarySearchTree<string> tree = new BinarySearchTree<string>();
long counter = 0, start, end, total = 0;
//Inserting
FileStream fs = new FileStream("google.txt", FileMode.Open);
StreamReader reader = new StreamReader(fs);
string line = null;
while((line = reader.ReadLine()) != null)
foreach(string word in line.Split(' '))
{
start = Environment.TickCount;
tree.Insert(word);
end = Environment.TickCount;
total += end - start;
counter += 1;
}
reader.Close();
Console.Out.WriteLine("time elapsed inserting {0} words: {1} seconds", counter, total / 1000D);
Console.Out.WriteLine("approx. {0} words per second", counter / (total / 1000D));
//writing new file
FileStream fs2 = new FileStream("ordered_words.txt", FileMode.Create, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs2);
start = Environment.TickCount;
IList<string> list = tree.TraverseToList(TraversalType.Inorder);
end = Environment.TickCount;
Console.Out.WriteLine("time elapsed traversing and generating the list for {0} elements: {1} seconds", counter, (end - start) / 1000D);
Console.Out.Write("writing file...");
for(int i = 0; i < list.Length; i++)
sw.WriteLine(list[i]);
sw.Close();
Console.Out.WriteLine();
string c = "Ford";
string c2 = "created";
//Console.Out.WriteLine("contains {0}?", c);
//Console.Out.WriteLine(tree.Contains(c));
//Console.Out.WriteLine(tree.Search("created"));
//Console.Out.WriteLine(tree.Remove(c));
//Console.Out.WriteLine(tree.Remove("Shortly"));
//Console.Out.WriteLine(tree.Contains(c2));
//Console.Out.WriteLine(tree.Contains(c));
list = tree.TraverseToList(TraversalType.BreadthFirst);
for(int i = 0; i < list.Length; i++)
Console.Out.WriteLine(list[i]);
}