#include <iostream>
#include <cstdlib>

using namespace std;

class arbol {
    private:
       char    info;
       arbol*  izq;
       arbol*  der;
 
    public:
      arbol(char i, arbol* iz=NULL, arbol* de=NULL);
      ostream& Pre(ostream& out) const;
      ostream& En(ostream& out) const;
      ostream& Post(ostream& out) const;
};

arbol::arbol(char i, arbol* iz, arbol* de)
{
    info= i;
    izq= iz;
    der= de;
}

ostream& arbol::Pre(ostream& out) const
{
   out << info;
   if (izq!=NULL)
      izq->Pre(out);
   if (der!=NULL)
      der->Pre(out);
   return out;
}

ostream& arbol::En(ostream& out) const
{
   if (izq!=NULL)
      izq->En(out);
   out << info;
   if (der!=NULL)
      der->En(out);
   return out;
}


ostream& arbol::Post(ostream& out) const
{
   if (izq!=NULL)
      izq->Post(out);
   if (der!=NULL)
      der->Post(out);
   out << info;
   return out;
}


  
int main(int argc, char* argv[])
{
    arbol*  a= new arbol('+',
                 new arbol('/', 
                   new arbol('+',
                      new arbol('a'),
                      new arbol('b')
                   ),
                   new arbol('c')
                 ),
                 new arbol('d')
               );   

    cout << "Pre: ";
    a->Pre(cout) << endl;
    cout << "En:  ";
    a->En(cout) << endl;
    cout << "Post:";
    a->Post(cout) << endl;
      
    return EXIT_SUCCESS; 
}


