當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。