From 9fe033ea88c2f705ec18c232873d056e0c229d72 Mon Sep 17 00:00:00 2001 From: Gaspard Coulet Date: Wed, 28 Apr 2021 23:05:53 +0200 Subject: Initial commit --- sem_4/Algo/TP4/AB.cpp | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 sem_4/Algo/TP4/AB.cpp (limited to 'sem_4/Algo/TP4/AB.cpp') diff --git a/sem_4/Algo/TP4/AB.cpp b/sem_4/Algo/TP4/AB.cpp new file mode 100644 index 0000000..379387e --- /dev/null +++ b/sem_4/Algo/TP4/AB.cpp @@ -0,0 +1,72 @@ +//AB.cpp + +#include "AB.h" + + +Sommet::Sommet(Valeur v){ + racine = v; + SAG = NULL; + SAD = NULL; + Pere = NULL; +} + +Sommet::Sommet(Sommet& s){ + racine = s.racine; + SAG = s.SAG; + SAD = s.SAD; + +} + + +bool Sommet::FeuilleP(){ + if (SAG == SAD && SAG == NULL){ + return true; + } + return false; +} + + +void Sommet::SupprimerSAG(){ + if (!FeuilleP()){ + SAG->SupprimerSAG(); + delete SAG; + } +} + + +void Sommet::SupprimerSAD(){ + if (!FeuilleP()){ + SAD->SupprimerSAD(); + delete SAD; + } +} + + +void Sommet::GrefferSAG(AB g){ + SupprimerSAG(); + SAG = g; + g->Pere = this; + g->FGP= true; + } + +void Sommet::GrefferSAD(AB d){ + SupprimerSAD(); + SAD=d; + d->Pere=this; + d->FGP=false; + } + + +void Sommet::RemplacerPourLePerePar(AB Ar){ + //le pere existe + if ( FGP ){ + Pere->GrefferSAG(Ar); +} +else { + Pere->GrefferSAD(Ar); +} +} + + +/*Question 1 : L'etiquette d'un sommet est dans "racine", on voit que l'arbo est binaire car chaque sommet ne peut avoir que 2 fils au maximum. +*/ -- cgit v1.2.3