當前位置: 首頁>>代碼示例>>C#>>正文


C# BinaryTree.ToString方法代碼示例

本文整理匯總了C#中BinaryTree.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# BinaryTree.ToString方法的具體用法?C# BinaryTree.ToString怎麽用?C# BinaryTree.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在BinaryTree的用法示例。


在下文中一共展示了BinaryTree.ToString方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DeleteWhereOnlyRootExists

        public void DeleteWhereOnlyRootExists()
        {
            var root = new Node(7);
            var tree = new BinaryTree(root);
            tree.Delete(7);

            Assert.AreEqual(String.Empty, tree.ToString());
        }
開發者ID:kawillia,項目名稱:Trees,代碼行數:8,代碼來源:BinaryTreeTests.cs

示例2: DeleteFromLeftOfRootNodeIsRemoved

        public void DeleteFromLeftOfRootNodeIsRemoved()
        {
            var tree = new BinaryTree(null);
            tree.Insert(7);
            tree.Insert(1);
            tree.Insert(0);
            tree.Insert(3);
            tree.Insert(2);
            tree.Insert(5);
            tree.Insert(4);
            tree.Insert(6);
            tree.Insert(9);
            tree.Insert(8);
            tree.Insert(10);
            tree.Delete(1);

            Assert.AreEqual("7,2,0,3,5,4,6,9,8,10", tree.ToString());
        }
開發者ID:kawillia,項目名稱:Trees,代碼行數:18,代碼來源:BinaryTreeTests.cs

示例3: Random

 public void Random()
 {
     BinaryTree<int> Tree = new BinaryTree<int>();
     System.Collections.Generic.List<int> Values = new System.Collections.Generic.List<int>();
     System.Random Rand = new System.Random();
     for (int x = 0; x < 10; ++x)
     {
         int Value = Rand.Next();
         Values.Add(Value);
         Tree.Add(Value);
     }
     for (int x = 0; x < 10; ++x)
     {
         Assert.Contains(Values[x], Tree);
     }
     Values.Sort();
     Assert.Equal(Values.ToString(x => x.ToString(), " "), Tree.ToString());
 }
開發者ID:gwilkinson,項目名稱:Craig-s-Utility-Library,代碼行數:18,代碼來源:BTree.cs

示例4: Random

 public void Random()
 {
     BinaryTree<int> Tree = new BinaryTree<int>();
     System.Collections.Generic.List<int> Values = new System.Collections.Generic.List<int>();
     System.Random Rand = new System.Random();
     for (int x = 0; x < 10; ++x)
     {
         int Value = Rand.Next();
         Values.Add(Value);
         Tree.Add(Value);
     }
     for (int x = 0; x < 10; ++x)
     {
         Assert.Contains(Values[x], Tree);
     }
     Values.Sort();
     StringBuilder Builder = new StringBuilder();
     Values.ForEach((x) => Builder.Append(x.ToString() + " "));
     Assert.Equal(Builder.ToString(), Tree.ToString());
 }
開發者ID:JKLFA,項目名稱:Craig-s-Utility-Library,代碼行數:20,代碼來源:BTree.cs

示例5: Main

    static void Main(string[] args)
    {
        BinaryTree<int> firstTree = new BinaryTree<int>();
        firstTree.AddNode(13);
        firstTree.AddNode(5);
        firstTree.AddNode(12);
        firstTree.AddNode(14);
        firstTree.AddNode(18);
        firstTree.AddNode(15);
        firstTree.AddNode(19);
        firstTree.AddNode(20);
        firstTree.AddNode(13);
        firstTree.AddNode(22);
        firstTree.AddNode(14);
        firstTree.AddNode(18);
        firstTree.AddNode(15);
        firstTree.AddNode(19);
        firstTree.AddNode(20);
        firstTree.AddNode(13);
        firstTree.AddNode(22);

        Console.WriteLine("The first tree - ToString()");
        Console.WriteLine(firstTree.ToString());
        Console.WriteLine();

        BinaryTree<int> secondTree = new BinaryTree<int>();
        secondTree.AddNode(13);
        secondTree.AddNode(5);
        secondTree.AddNode(12);
        secondTree.AddNode(14);
        secondTree.AddNode(18);
        secondTree.AddNode(15);
        secondTree.AddNode(19);
        secondTree.AddNode(20);
        secondTree.AddNode(13);
        secondTree.AddNode(22);

        Console.WriteLine("The second tree - foreach");
        foreach (var node in secondTree)
        {
            Console.Write(node + " ");
        }
        Console.WriteLine();
        Console.WriteLine();
        
        secondTree.DeleteElement(18);
        secondTree.DeleteElement(5);
        secondTree.DeleteElement(12);
        secondTree.DeleteElement(22);
        secondTree.DeleteElement(14);

        Console.WriteLine("The second tree after deleting elements - ToString()");
        Console.WriteLine(secondTree.ToString());
        Console.WriteLine();
        
        //Cloning demonstation
        BinaryTree<int> thirdTree = secondTree.Clone();
        Console.WriteLine("The third tree - ToString()");
        Console.WriteLine(thirdTree.ToString());
        Console.WriteLine();

        if (firstTree != thirdTree)
        {
            Console.WriteLine("The trees are NOT equal!");
        }
        Console.WriteLine();

        if (secondTree.Equals(thirdTree))
        {
            Console.WriteLine("The trees are equal!");
        }
        Console.WriteLine();

        //Search method demonstration - returns bool value
        Console.WriteLine("Found? {0}", thirdTree.Search(23));
        Console.WriteLine("Found? {0}", thirdTree.Search(20));
        Console.WriteLine("Found? {0}", firstTree.Search(-2220));
        Console.WriteLine("Found? {0}", secondTree.Search(1387));
        Console.WriteLine("Found? {0}", firstTree.Search(5));
        Console.WriteLine();

        //---------------------------------------------------------
        //Also we can create the tree using directly the constructor

        BinaryTree<string> fourthTree = new BinaryTree<string>("Hi", new BinaryTree<string>("there", new BinaryTree<string>("mate"), new BinaryTree<string>("What's")), new BinaryTree<string>("up"));
        Console.WriteLine("Fourth tree - ToString()");
        Console.WriteLine(fourthTree.ToString());
    }
開發者ID:ScreeM92,項目名稱:Software-University,代碼行數:88,代碼來源:BST.cs

示例6: InsertWithNoRootSetsRoot

        public void InsertWithNoRootSetsRoot()
        {
            var tree = new BinaryTree(null);
            tree.Insert(1);

            Assert.AreEqual("1", tree.ToString());
        }
開發者ID:kawillia,項目名稱:Trees,代碼行數:7,代碼來源:BinaryTreeTests.cs

示例7: InsertValueLessThanRootSetsLeft

        public void InsertValueLessThanRootSetsLeft()
        {
            var tree = new BinaryTree(null);
            tree.Insert(7);
            tree.Insert(1);

            Assert.AreEqual("7,1", tree.ToString());
        }
開發者ID:kawillia,項目名稱:Trees,代碼行數:8,代碼來源:BinaryTreeTests.cs

示例8: InsertValueGreaterThanRootSetsRight

        public void InsertValueGreaterThanRootSetsRight()
        {
            var tree = new BinaryTree(null);
            tree.Insert(7);
            tree.Insert(9);

            Assert.AreEqual("7,9", tree.ToString());
        }
開發者ID:kawillia,項目名稱:Trees,代碼行數:8,代碼來源:BinaryTreeTests.cs

示例9: InsertFullTreeTest

        public void InsertFullTreeTest()
        {
            var tree = new BinaryTree(null);
            tree.Insert(7);
            tree.Insert(1);
            tree.Insert(0);
            tree.Insert(3);
            tree.Insert(2);
            tree.Insert(5);
            tree.Insert(4);
            tree.Insert(6);
            tree.Insert(9);
            tree.Insert(8);
            tree.Insert(10);

            Assert.AreEqual("7,1,0,3,2,5,4,6,9,8,10", tree.ToString());
        }
開發者ID:kawillia,項目名稱:Trees,代碼行數:17,代碼來源:BinaryTreeTests.cs


注:本文中的BinaryTree.ToString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。