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/TP7/ArbreBinaireRecherche.cpp | 95 +++++++++++++++++++++++++++++ sem_4/Algo/TP7/ArbreBinaireRecherche.h | 57 +++++++++++++++++ sem_4/Algo/TP7/SortieLatex.cpp | 101 +++++++++++++++++++++++++++++++ sem_4/Algo/TP7/TPABR.pdf | Bin 0 -> 191051 bytes 4 files changed, 253 insertions(+) create mode 100644 sem_4/Algo/TP7/ArbreBinaireRecherche.cpp create mode 100644 sem_4/Algo/TP7/ArbreBinaireRecherche.h create mode 100644 sem_4/Algo/TP7/SortieLatex.cpp create mode 100644 sem_4/Algo/TP7/TPABR.pdf (limited to 'sem_4/Algo/TP7') diff --git a/sem_4/Algo/TP7/ArbreBinaireRecherche.cpp b/sem_4/Algo/TP7/ArbreBinaireRecherche.cpp new file mode 100644 index 0000000..ecd5af9 --- /dev/null +++ b/sem_4/Algo/TP7/ArbreBinaireRecherche.cpp @@ -0,0 +1,95 @@ +#include "ArbreBinaireRecherche.h" + +SommetABR::SommetABR(Valeur v){ + racine=v; SAG=NULL; SAD=NULL;Pere=NULL; +} + +SommetABR::SommetABR(SommetABR& s){ + racine=s.racine; SAG=NULL; SAD=NULL; + if (s.SAG) GrefferSAG(new SommetABR(*(s.SAG))); + if (s.SAD) GrefferSAD(new SommetABR(*(s.SAD))); +} + +ABR SommetABR::PlusPetit(){ + if (this->SAG==NULL){ + return this; + } + else { + return this->SAG->PlusPetit(); + } +} + +ABR SommetABR::RechercherValeur(Valeur v){ + if (this!= NULL){ + if( v < this->racine){ + this->SAG->RechercherValeur(v); + } + else if (v > this->racine){ + this->SAD->RechercherValeur(v); + } + else if ( v == this->racine){ + return this; + } + } + return NULL; +} + +void SommetABR::InsererValeur(Valeur v){ + if (v < racine){ + if (SAG!=NULL){ + SAG->InsererValeur(v); + } + else { + GrefferSAG(SommetABR(v)); + } + } + else { + if (SAD!=NULL){ + SAD->InsererValeur(v); + } + else { + GrefferSAD(SommetABR(v)); + } + } +} + +ABR SommetABR::SupMin(){ + SupprimerValeur(PlusPetit()->racine); + return this; +} + + +ABR SommetABR::SupprimerValeur(Valeur v){ + if ( this!=NULL){ + if (v < racine){ + SAG->SupprimerValeur(v); + } + else if ( v > racine){ + SAD->SupprimerValeur(v); + } + else { + this->racine = this->SAD->racine; + } + } + return NULL; +} + + + + + +int main() { + ABR A1=new SommetABR(11); + ABR A2=new SommetABR(9); + ABR A3=new SommetABR(14); + ABR A4=new SommetABR(3); + ABR A5=new SommetABR(20); + A1->GrefferSAG(A2); + A1->GrefferSAD(A3); + A2->GrefferSAG(A4); + A3->GrefferSAD(A5); + std::cout<RechercherValeur(11)< +#include + + +#include +#include + + +using namespace std; + + +typedef int Valeur; + +class SommetABR; + +typedef SommetABR* ABR; + +class SommetABR { + public: + Valeur racine; + ABR Pere,SAG, SAD; + bool FGP; + + void GrefferSAG(ABR g); + void GrefferSAD(ABR d); + + SommetABR(Valeur v); + SommetABR(SommetABR& s); + + + void SupprimerSAG(); + void SupprimerSAD(); + + bool FeuilleP(); + + void RemplacerPourLePerePar(ABR); + + std::string* TikzRecursABR(int ligne,int gauche, int droite, int numeroPere, int typeFils, ABR Ar); + +// ABR + + ABR PlusPetit(); + ABR RechercherValeur(Valeur v); + void InsererValeur(Valeur v); + ABR SupprimerValeur(Valeur v); // notez la dissym�trie + ABR SupMin(); +}; + + + //void SortieLatex(ABR, std::string filepath); + + + +#endif diff --git a/sem_4/Algo/TP7/SortieLatex.cpp b/sem_4/Algo/TP7/SortieLatex.cpp new file mode 100644 index 0000000..e5354e6 --- /dev/null +++ b/sem_4/Algo/TP7/SortieLatex.cpp @@ -0,0 +1,101 @@ +//SortieLatex.cpp + +#include +#include +#include + +typedef int Valeur; + +class SommetABR; + +typedef SommetABR* ABR; + +void SortieLatex(ABR Ar); + +class SommetABR { + protected: + Valeur racine; + ABR Pere,SAG, SAD; + + int hauteur,balanceGmoinsD; + + public: + SommetABR(Valeur v); + SommetABR(SommetABR& s); + + ABR remonterToutEnHaut(); + + void GrefferSAG(ABR g); + void GrefferSAD(ABR d); + + void SupprimerSAG(); + void SupprimerSAD(); + + bool FeuilleP(); + + void RemplacerPourLePerePar(ABR); + + friend std::string* TikzRecursABR(int ligne,int gauche, int droite, int numeroPere, int typeFils, ABR Ar); + + +}; + +std::string* TikzRecursABR(int ligne,int gauche, int droite, int numeroPere, int typeFils, ABR Ar); + + + +std::string * TikzRecursABR(int ligne,int gauche, int droite, int numeroPere, int typeFils, ABR Ar){ + std::ostringstream ossnum, osslign,osscol,ossnumPere, ossbal, ossnum2Pere,ossnumRac; + + std::string stres(""); + + if (Ar) { + ossnumPere<racine; + if (Ar->Pere )ossnum2Pere<Pere->racine; else ossnum2Pere<<0; + int numero; + if (typeFils==-1) numero=1; else numero= 2*numeroPere + typeFils; + ossnum<SAG) stres+=*TikzRecursABR(ligne -1 ,gauche,mil-1, numero,0,Ar->SAG); + if (Ar->SAD) stres+=*TikzRecursABR(ligne - 1,mil+1,droite, numero,1,Ar->SAD); + } + return new std::string(stres); +} + +std::string * TikzABR(ABR Ar){ + return TikzRecursABR(1,1,10,1, -1,Ar); +} + + + void SortieLatex(ABR Ar, std::string filepath){ //don't insert garbage in filepath, its std::system-ised. + std::ofstream fichier(filepath.c_str(), std::ios::out | std::ios::trunc); + std::string preamb ("\\documentclass{article} \n \\usepackage{tikz} \n \\begin{document} \n \\resizebox{300pt}{!}{\n \\begin{tikzpicture}\n"); + std::cout<&1 isnt enough to mute pdflatex... + system_CARE << "mkdir pdflatex_temp > /dev/null 2>&1;" + << "init_texlive;"<< "pdflatex -output-directory=\"./pdflatex_temp\" -interaction=nonstopmode \"" << filepath << "\" >/dev/null 2>&1;" + <<"mv ./pdflatex_temp/*.pdf ./ > /dev/null 2>&1;"; + std::system(system_CARE.str().c_str()); + return; +} + + + +// g++ -c SortieLatex.cpp diff --git a/sem_4/Algo/TP7/TPABR.pdf b/sem_4/Algo/TP7/TPABR.pdf new file mode 100644 index 0000000..beabb1b Binary files /dev/null and b/sem_4/Algo/TP7/TPABR.pdf differ -- cgit v1.2.3