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


C# BinarySearchTree.Postorder方法代碼示例

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


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

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

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


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