summaryrefslogtreecommitdiff
path: root/sem_4/Algo/TP4/AB.cpp
diff options
context:
space:
mode:
authorGaspard Coulet <gaspard.coulet@mines-ales.org>2021-04-28 23:05:53 +0200
committerGaspard Coulet <gaspard.coulet@mines-ales.org>2021-04-28 23:05:53 +0200
commit9fe033ea88c2f705ec18c232873d056e0c229d72 (patch)
tree0647dc8c51610c7336c88c04de2068ea14b21e17 /sem_4/Algo/TP4/AB.cpp
Initial commit
Diffstat (limited to 'sem_4/Algo/TP4/AB.cpp')
-rw-r--r--sem_4/Algo/TP4/AB.cpp72
1 files changed, 72 insertions, 0 deletions
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.
+*/