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


C# BinarySearchTree.TraversePost方法代碼示例

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


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

示例1: UnitTest

 public static void UnitTest()
 {
     Console.WriteLine ("----- Testing BinarySearchTree<int> -----");
     Console.Write ("Creating new BinarySearchTree of type <int>...");
     BinarySearchTree<int> test = new BinarySearchTree<int> (); d ();
     Console.Write ("Adding value 50...");
     test.Add (50); d ();
     Console.Write ("Adding value 25...");
     test.Add (25); d ();
     Console.Write ("Adding value 75...");
     test.Add (75); d ();
     Console.Write ("Checking for correct structure (25/50\\75)...");
     Debug.Assert (test.root.value == 50);
     Debug.Assert (test.root.nodes[0].value == 25);
     Debug.Assert (test.root.nodes[1].value == 75);
     d ();
     Console.Write ("Checking if BinarySearchTree.Contains(75) works...");
     Debug.Assert (test.Contains(75)); d ();
     Console.Write ("Testing BinarySearchTree.TraversePre()...");
     Debug.Assert( test.TraversePre ((x) => Console.Write (x.value + " ")) == "50 25 75 "); d ();
     Console.Write ("Testing BinarySearchTree.TraverseInOrder()...");
     Debug.Assert( test.TraverseInOrder ((x) => Console.Write (x.value + " ")) == "25 50 75 "); d ();
     Console.Write ("Testing BinarySearchTree.TraversePost()...");
     Debug.Assert( test.TraversePost ((x) => Console.Write (x.value + " ")) == "25 75 50 "); d ();
     Console.WriteLine ("----- Testing BinarySearchTree<string> -----");
     Console.Write ("Creating new BinarySearchTree of type <string> with custom IComparer...");
     BinarySearchTree<string> foo = new BinarySearchTree<string> ( new StringComparer() ); d ();
     Console.Write ("Adding value Urist McSmashes...");
     foo.Add ("Urist McSmashes"); d ();
     Console.Write ("Adding value Gordon Freeman...");
     foo.Add ("Gordon Freeman"); d ();
     Console.Write ("Adding value Winston Smith...");
     foo.Add ("Winston Smith"); d ();
     Console.Write ("Checking for correct structure (Gordon Freeman/Urist McSmashes\\Winston Smith)...");
     Debug.Assert (foo.root.value == "Urist McSmashes");
     Debug.Assert (foo.root.nodes[0].value == "Gordon Freeman");
     Debug.Assert (foo.root.nodes[1].value == "Winston Smith");
     d ();
     Console.WriteLine ("----- Testing BinaryExpressionTree -----");
     Console.Write ("Creating new BinaryExpressionTree with expression \"5 + 2 * 8 - 6 / 4\"...");
     BinaryExpressionTree bar = new BinaryExpressionTree ("5 + 2 * 8 - 6 / 4"); d ();
     Console.Write ("Checking for correct structure...");
     Debug.Assert( bar.TraverseInOrder ((x) => Console.Write (x.value + " ")) == "4 47 6 45 8 42 2 43 5 ");
     Debug.Assert( bar.root.value == 45 ); // -
     Debug.Assert( bar.root.nodes[0].value == 47 ); // /
     Debug.Assert( bar.root.nodes[0].nodes[0].value == 4 );
     Debug.Assert( bar.root.nodes[0].nodes[1].value == 6 );
     Debug.Assert( bar.root.nodes[1].value == 43 ); // +
     Debug.Assert( bar.root.nodes[1].nodes[1].value == 5 );
     Debug.Assert( bar.root.nodes[1].nodes[0].value == 42 ); // *
     Debug.Assert( bar.root.nodes[1].nodes[0].nodes[0].value == 8 );
     Debug.Assert( bar.root.nodes[1].nodes[0].nodes[1].value == 2 );
     d ();
     Console.Write ("Checking for correct answer \"5 + 2 * 8 - 6 / 4\" = " + (5.0 + 2.0 * 8.0 - 6.0 / 4.0) + "...");
     Debug.Assert (bar.Eval () == (5.0 + 2.0 * 8.0 - 6.0 / 4.0)); d ();
     Console.WriteLine ("Everything appears to be in order! Although asserts in C# don't actually end execution so there's no real way for me to know!");
 }
開發者ID:naelstrof,項目名稱:2420-Binary-Trees,代碼行數:57,代碼來源:Program.cs


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