当前位置: 首页>>代码示例>>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;未经允许,请勿转载。