当前位置: 首页>>代码示例>>C#>>正文


C# BinarySearchTree.TraverseToList方法代码示例

本文整理汇总了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]);
    }
开发者ID:omarkhd,项目名称:dsa-cs,代码行数:50,代码来源:test1.cs


注:本文中的BinarySearchTree.TraverseToList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。