esto es una implementacion de una clase arbol
asi se ve horrible pero es mucho mas facil que eso, pasalo a tu compilador habitual :p
template <class Elem>
class Arbre2 {
class Noeud {
friend class Arbre2<Elem>;
Elem info;
Noeud *fg, *fd;
Noeud (const Elem& E, Noeud* G=NULL, Noeud* D=NULL):
info(E), fg(G), fd(D) {}
};
public:
typedef Noeud* Place;
private:
Place rac;
inline static Place Copy (Place);
inline static void Cancel(Place&);
public:
bool Existe (Place p) const {return p != NULL;}
Place Rac () const {return rac;}
Place FilsG (Place p) const {return p->fg;}
Place FilsD (Place p) const {return p->fd;}
Elem& operator[] (Place p) {return p->info;}
void InsG (const Elem& E, Place p) {Cancel(p->fg); p->fg = new Noeud(E);}
void InsD (const Elem& E, Place p) {Cancel(p->fd); p->fd = new Noeud(E);}
void InsG (const Arbre2& A, Place p) {Cancel(p->fg); p->fg = Copy(A.rac);}
void InsD (const Arbre2& A, Place p) {Cancel(p->fd); p->fd = Copy(A.rac);}
void SupG (Place p) {Cancel(p->fg);}
void SupD (Place p) {Cancel(p->fd);}
// Constructores
Arbre2 (const Elem& E): rac(new Noeud(E)) {}
Arbre2 (): rac(NULL) {}
Arbre2 (const Arbre2& A, Place p): rac(Copy(p)) {}
Arbre2 (const Arbre2& A): rac(Copy(A.rac)) {}
Arbre2& operator= (const Arbre2& A) {
if (this != &A) {Cancel(rac); rac = Copy(A.rac);}
return *this;
}
~Arbre2 () {Cancel(rac);}
};
template <class Elem>
Arbre2<Elem>::Place Arbre2<Elem>::Copy (Place p) {
return p ? new Noeud(p->info, Copy(p->fg), Copy(p->fd)) : NULL;
}
template <class Elem>
void Arbre2<Elem>::Cancel (Place& p) {
if (p) {
Cancel(p->fg);
Cancel(p->fd);
delete p; p = NULL;
}
}