Пример #1
0
 IEnumerable <int> TraversePostOrder(TraverseNode root)
 {
     if (root.Left != null)
     {
         foreach (var value in TraversePostOrder(root.Left).ToList())
         {
             yield return(value);
         }
     }
     if (root.Right != null)
     {
         foreach (var value in TraversePostOrder(root.Right).ToList())
         {
             yield return(value);
         }
     }
     yield return(root.Value);
 }
Пример #2
0
        void TestPostOrderTraversal(TraverseNode root, int[] expected)
        {
            var actual = TraversePostOrder(root).ToList();

            Assert.True(expected.SequenceEqual(actual));
        }