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


C# BinarySearchTree.FindMax方法代碼示例

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


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

示例1: Main

        static void Main(string[] args)
        {
            Console.Title = "Binary search tree";

            // Initialize a BST which will contain integers
            BinarySearchTree<int> intTree = new BinarySearchTree<int>();

            Random randomGenerathor = new Random(DateTime.Now.Millisecond);
            StringBuilder trace = new StringBuilder();

            // Insert 10 random integers into the intTree
            for (int i = 0; i < 10; i++)
            {
                int randomInt = randomGenerathor.Next(1, 500);
                intTree.Insert(randomInt);
                trace.Append(randomInt);
                trace.Append(" ");
            }

            // Clone the intTree
            dynamic newTree = intTree.Clone();
            StringBuilder newTrace = new StringBuilder(trace.ToString());

            // Insert 3 new random integers into the newTree
            for (int i = 0; i < 3; i++)
            {
                int randomInt = randomGenerathor.Next(1, 500);
                newTree.Insert(randomInt); // May throw Argument exception if the element is already exist in the tree
                newTrace.Append(randomInt);
                newTrace.Append(" ");
            }

            // Find the largest value in the intTree
            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.WriteLine("Max element: {0}", intTree.FindMax());

            // Find the largest value in the newTree
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.WriteLine("\nMax element: {0}", newTree.FindMax());

            // Find the smallest value in the intTree
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("\nMin element: {0}", intTree.FindMin());

            // Find the smallest value in the newTree
            Console.ForegroundColor = ConsoleColor.DarkCyan;
            Console.WriteLine("\nMin element: {0}", newTree.FindMin());

            // Find the hash code of the intTree
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("\nHashcode: {0}", intTree.GetHashCode());

            // Find the hash code of the newTree
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.WriteLine("\nHashcode: {0}", newTree.GetHashCode());

            // Find the root of the intTree
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("\nRoot: {0}", intTree.Root.Element);

            // Find the root of the newTree
            Console.ForegroundColor = ConsoleColor.DarkMagenta;
            Console.WriteLine("\nRoot: {0}", newTree.Root.Element);

            // The order in which the elements were added to the intTree
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("\nTrace: {0}", trace);

            // The order in which the elements were added to the newTree
            Console.ForegroundColor = ConsoleColor.DarkRed;
            Console.WriteLine("\nTrace: {0}", newTrace);

            // A textual representation of the intTree
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("\nFirst Tree: \n{0}", intTree);          

            // A textual representation of the newTree
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine("\nSecond Tree: \n{0}", newTree);

            Console.WriteLine();
            Console.ResetColor();
        }
開發者ID:nikolay-radkov,項目名稱:Telerik-Academy,代碼行數:83,代碼來源:Demo.cs

示例2: FindMaxTreeEmptyTest

        public void FindMaxTreeEmptyTest()
        {
            BinarySearchTree<int> bst = new BinarySearchTree<int>();

            bst.FindMax();
        }
開發者ID:taoxiease,項目名稱:asegrp,代碼行數:6,代碼來源:BinarySearchTreeTest.cs

示例3: FindMaxTest

        public void FindMaxTest([PexAssumeUnderTest]int[] elements)
        {
            BinarySearchTree<int> bst = new BinarySearchTree<int>(elements);
            //Compute the maximum element
            int maxValue = Int32.MinValue;
            foreach (int val in elements)
                maxValue = maxValue < val ? val : maxValue;

            PexAssert.AreEqual(maxValue, bst.FindMax());
        }
開發者ID:taoxiease,項目名稱:asegrp,代碼行數:10,代碼來源:BinarySearchTreeTest.cs

示例4: FindMaxTest

        public void FindMaxTest()
        {
            BinarySearchTree<int> bst = new BinarySearchTree<int> {12, 8, 42, 6, 11};

            Assert.AreEqual(42, bst.FindMax());
        }
開發者ID:taoxiease,項目名稱:asegrp,代碼行數:6,代碼來源:BinarySearchTreeTest.cs


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