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


C# BinaryTree.Insert方法代碼示例

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


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

示例1: Main

 static void Main(string[] args)
 {
     BinaryTree<int> intTree = new BinaryTree<int>(new Node<int>(5));
     intTree.Insert(4);
     intTree.Insert(6);
     intTree.Insert(7);
     Console.WriteLine("Tree has {0} elements", intTree.Elements);
     Node<int> n = intTree[2];
     Console.ReadLine();
 }
開發者ID:bergmannf,項目名稱:hw_spas10,代碼行數:10,代碼來源:Program.cs

示例2: Main

        static void Main(string[] args)
        {
            BinaryTree<int> tree = new BinaryTree<int>();
            tree.Insert(2);
            tree.Insert(3);
            tree.Insert(5);
            tree.Insert(8);
            tree.Insert(11);
            tree.Insert(200);
            tree.Insert(120);
            tree.Insert(600);
            Console.WriteLine(tree);
            Console.WriteLine(tree.Count);
           
            tree.Remove(2);
            tree.Remove(5);
            tree.Remove(8);
            Console.WriteLine(tree);
            tree.Remove(11);
            tree.Remove(200);
            tree.Remove(120);
            tree.Remove(600);
            tree.Remove(3);
            Console.WriteLine(tree);
            Console.WriteLine(tree.Count);

            tree.Insert(10);
            tree.Insert(20);
            tree.Insert(30);
            tree.Insert(60);
            tree.Insert(1);
            tree.Insert(500);
            tree.Insert(2);
            Console.WriteLine(tree);
            Console.WriteLine(tree.Count);

            var newTree = new BinaryTree<int>();
            newTree.Insert(10);
            newTree.Insert(20);
            newTree.Insert(30);
            newTree.Insert(60);
            newTree.Insert(1);
            newTree.Insert(500);
            newTree.Insert(2);
            Console.WriteLine(newTree);
            Console.WriteLine(newTree.Count);
            Console.WriteLine(tree.Equals(newTree));


            foreach (var value in tree)
            {
                Console.WriteLine(value);
            }

            BinaryTree<int> r = null;
            Console.WriteLine(tree.Equals(r));
            int a = 5; 
            Console.WriteLine(a.Equals(null));

        }
開發者ID:alex687,項目名稱:SoftUni-Homeworks,代碼行數:60,代碼來源:Program.cs

示例3: Main

 static void Main(string[] args)
 {
     BinaryTree<int> intTree = new BinaryTree<int>(new Node<int>(5));
     intTree.Insert(4);
     intTree.Insert(6);
     intTree.Insert(7);
     Console.WriteLine("Tree has {0} elements", intTree.Elements);
     foreach (int item in intTree)
     {
         Console.WriteLine("Item: {0}", item);
     }
     Console.WriteLine("After applying the delegate");
     intTree.Collect(Square);
     foreach (int item in intTree)
     {
         Console.WriteLine("Item: {0}", item);
     }
     Console.ReadLine();
 }
開發者ID:bergmannf,項目名稱:hw_spas10,代碼行數:19,代碼來源:Program.cs

示例4: 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;
        }
開發者ID:vpfau,項目名稱:Algorithms,代碼行數:23,代碼來源:Tree.cs

示例5: Main

 static void Main(string[] args)
 {
     BinaryTree<int> tree = new BinaryTree<int>();
     tree.Insert(5);
     tree.Insert(10);
     tree.Insert(2);
     tree.Insert(14);
     tree.Insert(1);
     tree.Insert(4);           
     tree.Insert(3);
     tree.Insert(7);
     tree.Insert(6);
     foreach (var e in tree)
     {
         Console.WriteLine(e);
     }
     Console.ReadKey();
 }
開發者ID:Stanislav-Berezovsky,項目名稱:BSU.ASP.1501.Day9.Berezovsky,代碼行數:18,代碼來源:Program.cs

示例6: Main

 static void Main(string[] args)
 {
     BinaryTree tree = new BinaryTree();
     Random rnd = new Random();
     for (int i = 0; i < 15; i++)
     {
         tree.Insert(rnd.Next(100));
     }
     Console.WriteLine("Inorder Traversal : ");
     tree.Inorder(tree.ReturnRoot());
     Console.WriteLine(" ");
     Console.WriteLine();
     Console.WriteLine("Preorder Traversal : ");
     tree.Preorder(tree.ReturnRoot());
     Console.WriteLine(" ");
     Console.WriteLine();
     Console.WriteLine("Postorder Traversal : ");
     tree.Postorder(tree.ReturnRoot());
     Console.WriteLine(" ");
     Console.ReadLine();
 }
開發者ID:syhestkiy,項目名稱:Kata,代碼行數:21,代碼來源:Program.cs

示例7: InsertWithNoRootSetsRoot

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

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

示例8: 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

示例9: 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

示例10: 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

示例11: 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


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