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


C# BinarySearchTree.Inorder方法代码示例

本文整理汇总了C#中BinarySearchTree.Inorder方法的典型用法代码示例。如果您正苦于以下问题:C# BinarySearchTree.Inorder方法的具体用法?C# BinarySearchTree.Inorder怎么用?C# BinarySearchTree.Inorder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinarySearchTree的用法示例。


在下文中一共展示了BinarySearchTree.Inorder方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BinaryTreeAlgorithms_Test

        public void BinaryTreeAlgorithms_Test()
        {
            var tree1 = new BinarySearchTree<int>();
            tree1.Add(24);
            tree1.Add(12);
            tree1.Add(15);
            tree1.Add(67);
            tree1.Add(32);
            tree1.Add(13);
            tree1.Add(89);
            tree1.Add(9);

            tree1.Remove(13);
            tree1.Remove(24);
            //Assert.IsTrue(tree1.PathSum(tree1.Root(), 45));
            //Assert.IsTrue(tree1.PathSum(tree1.Root(), 51));
            //Assert.IsFalse(tree1.PathSum(tree1.Root(), 42));

            //Assert.AreEqual(8, tree1.Size(tree1.Root()));

            //Assert.AreEqual(9, tree1.Minimum(tree1.Root()));

            //Assert.AreEqual(89, tree1.Maximum(tree1.Root()));

            //Assert.IsTrue(BinaryTree.AreTwoTreesEqual(tree1.Root(), tree2.Root()));

            Console.WriteLine("Inorder traversal ");
            tree1.Inorder(tree1.Root);
            Console.WriteLine(" ");

            TreeAlgorithms<int>.Mirror(tree1.Root);

            Console.WriteLine("Inorder traversal of the Mirror tree");
            tree1.Inorder(tree1.Root);
            Console.WriteLine(" ");

            Console.WriteLine();
            Console.WriteLine("Preorder traversal");
            tree1.Preorder(tree1.Root);
            Console.WriteLine(" ");

            Console.WriteLine();
            Console.WriteLine("Postorder traversal");
            tree1.Postorder(tree1.Root);
            Console.WriteLine(" ");
        }
开发者ID:SaurabhNijhawan,项目名称:CSharpAlgorithmsAndDataStructures,代码行数:46,代码来源:BinaryTreeAlgorithmsTests.cs

示例2: BinaryTreeAlgorithms_Mirror_Test

        public void BinaryTreeAlgorithms_Mirror_Test()
        {
            var tree1 = new BinarySearchTree<int>();
            tree1.Add(24);
            tree1.Add(12);
            tree1.Add(15);
            tree1.Add(67);
            tree1.Add(32);
            tree1.Add(13);
            tree1.Add(89);
            tree1.Add(9);

            Console.WriteLine("Inorder traversal ");
            tree1.Inorder(tree1.Root);
            Console.WriteLine(" ");

            TreeAlgorithms<int>.Mirror(tree1.Root);

            Console.WriteLine("Inorder traversal of the Mirror tree");
            tree1.Inorder(tree1.Root);
            Console.WriteLine(" ");
        }
开发者ID:SaurabhNijhawan,项目名称:CSharpAlgorithmsAndDataStructures,代码行数:22,代码来源:BinaryTreeAlgorithmsTests.cs

示例3: BinaryTree_Tests

        public void BinaryTree_Tests()
        {
            var tree1 = new BinarySearchTree<int>();
            tree1.Add(24);
            tree1.Add(12);
            tree1.Add(15);
            tree1.Add(67);
            tree1.Add(32);
            tree1.Add(13);
            tree1.Add(89);
            tree1.Add(9);

            var tree2 = new BinarySearchTree<int>();
            tree2.Add(24);
            tree2.Add(12);
            tree2.Add(15);
            tree2.Add(67);
            tree2.Add(32);
            tree2.Add(13);
            tree2.Add(89);
            tree2.Add(9);

            Console.WriteLine("Inorder traversal resulting Tree Sort");
            tree1.Inorder(tree1.Root);
            Console.WriteLine(" ");

            Console.WriteLine();
            Console.WriteLine("Preorder traversal");
            tree1.Preorder(tree1.Root);
            Console.WriteLine(" ");

            Console.WriteLine();
            Console.WriteLine("Postorder traversal");
            tree1.Postorder(tree1.Root);
            Console.WriteLine(" ");

            //Assert.IsTrue(tree1.PathSum(tree1.Root(), 45));
            //Assert.IsTrue(tree1.PathSum(tree1.Root(), 51));
            //Assert.IsFalse(tree1.PathSum(tree1.Root(), 42));

            //Assert.AreEqual(8, tree1.Size(tree1.Root()));

            //Assert.AreEqual(9, tree1.Minimum(tree1.Root()));

            //Assert.AreEqual(89, tree1.Maximum(tree1.Root()));

            //Assert.IsTrue(BinaryTree.AreTwoTreesEqual(tree1.Root(), tree2.Root()));
        }
开发者ID:SaurabhNijhawan,项目名称:CSharpAlgorithmsAndDataStructures,代码行数:48,代码来源:BinaryTreeTests.cs

示例4: Main

        //public static void Main(string[] args)
        //{
        //DoubleLinkedList<int> list = new DoubleLinkedList<int>();
        //SingleLinkedList<int> list = new SingleLinkedList<int>();
        //int index = 5;
        //Console.WriteLine("The ADD Method and toString");
        //Add Method and toString
        //list.Add(12);
        //list.Add(20);
        //list.Add(1);
        //list.Add(0);
        //list.Add(121);
        //list.Add(420);
        //list.Add(78);
        //list.Add(90);
        //list.Add(34);
        //list.Add(4);
        //Console.WriteLine(list.ToString());
        //Console.WriteLine("\nThe COUNT Method");
        //Console.WriteLine("The the count of this list is: " + list.Count);
        //Console.WriteLine("\nThe INSERT Method");
        //Console.WriteLine("I am inserting the number 22 at index: " + index);
        //list.Insert(22, index);
        //Console.WriteLine("New List: " + list.ToString());
        //Console.WriteLine("\nThe COUNT Method");
        //Console.WriteLine("The the count of this list is: " + list.Count);
        //Console.WriteLine("\nThe Get Method");
        //Console.WriteLine("What is at index " + index + ": " + list.Get(index));
        //Console.WriteLine("\nThe REMOVEAT Method");
        //Console.WriteLine("What is at index " + (list.Count - 1) + ": " + list.Get((list.Count - 1)));
        //Console.WriteLine("I am removing the element at index " + (list.Count - 1) + ": " + list.RemoveAt((list.Count - 1)));
        //Console.WriteLine("New List: " + list.ToString());
        //Console.WriteLine("\nThe COUNT Method");
        //Console.WriteLine("The the count of this list is: " + list.Count);
        //Console.WriteLine("\nThe INSERT Method");
        //Console.WriteLine("I am inserting the number 15 at index: " + );
        //list.Insert(15,(list.Count - 1));
        //Console.WriteLine("New List: " + list.ToString());
        //Console.WriteLine("\nThe COUNT Method");
        //Console.WriteLine("The the count of this list is: " + list.Count);
        //Console.WriteLine("\nThe SEARCH Method");
        //Console.WriteLine("Searching for 1: " + list.Search(1));
        //Console.WriteLine("\nThe REMOVE Method");
        //Console.WriteLine(list.Remove());
        //Console.WriteLine("New List: " + list.ToString());
        //Console.WriteLine("\nThe COUNT Method");
        //Console.WriteLine("The the count of this list is: " + list.Count);
        //Console.WriteLine("\nThe REMOVELAST Method");
        //Console.WriteLine(list.RemoveLast());
        //Console.WriteLine("New List: " + list.ToString());
        //Console.WriteLine("\nThe COUNT Method");
        //Console.WriteLine("The the count of this list is: " + list.Count);
        //Console.WriteLine("\nThe CLEAR Method");
        //list.Clear();
        //Console.WriteLine("New List: " + list.ToString());
        //    Console.WriteLine("\nThe REMOVEAT Method");
        //    Console.WriteLine("What is at index " + index + ": " + list.Get(index));
        //    //Console.WriteLine("I am removing the element at index " + index + ": " + list.RemoveAt(index));
        //    Console.WriteLine("New List: " + list.ToString());
        //    Console.WriteLine("\nThe COUNT Method");
        //    Console.WriteLine("The the count of this list is: " + list.Count);
        //}
        public static void Main(string[] args)
        {
            BinarySearchTree<int> bst = new BinarySearchTree<int>();

            bst.Add(24);
            bst.Add(10);
            bst.Add(1337);

            //bst.Add(50);
            //bst.Add(1472);
            //bst.Add(72);
            //bst.Add(1360);
            //bst.Add(1345);
            //bst.Add(54);

            //bst.Add(20);
            //bst.Add(9);
            //bst.Add(19);
            //bst.Add(14);
            //bst.Add(67);

            //bst.Add(35);
            //bst.Add(80);
            //bst.Add(65);
            //bst.Add(24);
            //bst.Add(5);

            Console.WriteLine("Count:" + bst.Count);
            //Console.WriteLine("\ncontains 24: " + bst.Contains(24));

            //Console.WriteLine("\ncontains 0: " + bst.Contains(0));

            //Console.WriteLine("\nInorder:" + bst.Inorder());

            //Console.WriteLine("\nRemove: I'm removing 17 : " + bst.Remove(17));
            Console.WriteLine("\nInorder:" + bst.Inorder());

            Console.WriteLine("\nRemove: I'm removing 24 : " + bst.Remove(24));
//.........这里部分代码省略.........
开发者ID:NUdbrown,项目名称:Algo2Assignments,代码行数:101,代码来源:Program.cs


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