| the big ben |
J ai recu cette classe tel quelle a un cour mais j ai qq probleme ... voir + bas !!!
Il me fait des erreurs aves mes constante NULL voir message plus bas D'avance merci Mon prog principal: #include "arbre2PL.h" void main() { Arbre2<int> A; } template <class Elem> class Arbre2 { class Noeud { friend class Arbre2<Elem>; Elem info; Noeud *pere, *fg, *fd; Noeud (const Elem& E, Noeud* P=NULL, Noeud* G=NULL, Noeud* D=NULL): info(E), pere(P), fg(G), fd(D) {} }; public: typedef Noeud* Place; private: Place rac; inline static Place Copy (Place, Place = NULL); inline static void Cancel(Place&); public: bool Existe (Place p) const {return p != NULL;} Place Rac () const {return rac;} Place Pere (Place p) const {return p->pere;} 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, p);} void InsD (const Elem& E, Place p) {Cancel(p->fd); p->fd = new Noeud(E, p);} void InsG (const Arbre2& A, Place p) {Cancel(p->fg); p->fg = Copy(A.rac, p);} void InsD (const Arbre2& A, Place p) {Cancel(p->fd); p->fd = Copy(A.rac, p);} void SupG (Place p) {Cancel(p->fg);} void SupD (Place p) {Cancel(p->fd);} // Constructeurs 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 s, Place p) { Place f = NULL; if (s) { f = new Noeud(s->info, p); f->fg = Copy(s->fg, f); f->fd = Copy(s->fd, f); } return f; } template <class Elem> void Arbre2<Elem>::Cancel (Place& p) { if (p) { Cancel(p->fg); Cancel(p->fd); delete p; p = NULL; } } [jfdsdjhfuetppo]--Message édité par The big ben--[/jfdsdjhfuetppo] |