#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;
}

istream& operator >> (istream& in, arbol*& p)
{
   int c= in.get();
   if (c=='.')
      {
       p= NULL;
       return in;
      }
   else
      {
       arbol* iz;
       arbol* de;
       in >> iz;
       in >> de;
       p= new arbol(c, iz, de);
       return in;
      }
}


  
int main(int argc, char* argv[])
{
    arbol* a;
    cout << "Dar a:\n";
    cin >> a;
    cout << "Pre: ";
    a->Pre(cout) << endl;
    cout << "En:  ";
    a->En(cout) << endl;
    cout << "Post:";
    a->Post(cout) << endl;
      
    return EXIT_SUCCESS; 
}


