Código
using System; using System.Collections; using System.Collections.Generic; namespace Arbol { static class Program { [STAThread] public static void Main() { SimpleTree<string> raiz1 = Formula; raiz1.Value = "-"; SimpleTreeNode<string> izq1 = raiz1.Children.Add("*"); SimpleTreeNode<string> der1 = raiz1.Children.Add("/"); SimpleTreeNode<string> izq2 = izq1.Children.Add("5"); SimpleTreeNode<string> der2 = izq1.Children.Add("3"); SimpleTreeNode<string> izq3 = der1.Children.Add("+"); SimpleTreeNode<string> der3 = der1.Children.Add("*"); SimpleTreeNode<string> izq4 = izq3.Children.Add("4"); SimpleTreeNode<string> der4 = izq3.Children.Add("3"); SimpleTreeNode<string> izq5 = der3.Children.Add("2"); SimpleTreeNode<string> der5 = der3.Children.Add("+"); SimpleTreeNode<string> izq6 = der5.Children.Add("1"); SimpleTreeNode<string> der6 = der5.Children.Add("2"); //Prefijo Console.Write("Prefijo: "); Prefijo(Formula); Console.ReadLine(); //Postfijo Console.Write("Postfijo: "); Postfijo(Formula); Console.ReadLine(); Console.ReadKey(); } public static void Prefijo(SimpleTreeNode<string> Subtree) { Console.Write("{0}", Subtree.Value); foreach (SimpleTreeNode<string> node in Subtree.Children) { Prefijo(node); } } public static void Postfijo(SimpleTreeNode<string> Subtree) { foreach (SimpleTreeNode<string> node in Subtree.Children) { Postfijo(node); } Console.Write("{0}", Subtree.Value); } } }