@ -0,0 +1,30 @@
|
|||||||
|
#ifndef ABR_H
|
||||||
|
#define ABR_H
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
typedef struct noeud {
|
||||||
|
int val;
|
||||||
|
struct noeud *fg, *fd;
|
||||||
|
} Noeud;
|
||||||
|
|
||||||
|
typedef Noeud* Abr;
|
||||||
|
|
||||||
|
typedef enum{FALSE, TRUE} Booleen;
|
||||||
|
|
||||||
|
Abr creerArbreVide(void);
|
||||||
|
Booleen estArbreVide(Abr a);
|
||||||
|
Noeud* creerNoeud(int val);
|
||||||
|
void insererEnFeuille(Abr* pta, int val);
|
||||||
|
void viderArbre(Abr* pta);
|
||||||
|
// void afficherCroissant(Abr a);
|
||||||
|
// void afficherDecroissant(Abr a);
|
||||||
|
void afficherNtab(int n);
|
||||||
|
void afficherCoucheRec(Abr a, int retrait);
|
||||||
|
void afficherCouche(Abr a);
|
||||||
|
Booleen rechercherVal(Abr a, int val);
|
||||||
|
Booleen supprimerVal(Abr* pta, int val);
|
||||||
|
|
||||||
|
|
||||||
|
#endif //ABR_H
|
@ -1,24 +0,0 @@
|
|||||||
#ifndef ABR_H
|
|
||||||
#define ABR_H
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
typedef struct noeud{
|
|
||||||
int val;
|
|
||||||
struct noeud *fg, *fd;
|
|
||||||
}Noeud;
|
|
||||||
|
|
||||||
typedef Noeud * Abr;
|
|
||||||
|
|
||||||
typedef enum{FALSE, TRUE} Booleen;
|
|
||||||
|
|
||||||
Abr creerArbrevide(void);
|
|
||||||
Booleen estArbreVide(Abr a);
|
|
||||||
Noeud* creerNoeud(int val);
|
|
||||||
void insererEnFeuille(Abr* pta, int val);
|
|
||||||
void viderArbre(Abr *pta);
|
|
||||||
void afficherCroissant(Abr a);
|
|
||||||
void afficherDecroissant(Abr a);
|
|
||||||
|
|
||||||
#endif //ABR_H
|
|
@ -1,61 +0,0 @@
|
|||||||
/**
|
|
||||||
* @file main.c
|
|
||||||
*
|
|
||||||
* @brief Fichier principal contenant les tests pour l'Arbre Binaire de Recherche (ABR).
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "abr.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Fonction de test pour les opérations sur l'ABR.
|
|
||||||
*/
|
|
||||||
void testAbr(void){
|
|
||||||
Abr a1 = creerArbrevide();
|
|
||||||
Abr a2 = creerArbrevide();
|
|
||||||
|
|
||||||
// Teste si l'arbre a1 est vide
|
|
||||||
estArbreVide(a1);
|
|
||||||
|
|
||||||
// Insère des valeurs dans l'arbre a2
|
|
||||||
insererEnFeuille(&a2, 10);
|
|
||||||
insererEnFeuille(&a2, 10);
|
|
||||||
insererEnFeuille(&a2, 11);
|
|
||||||
insererEnFeuille(&a2, 9);
|
|
||||||
|
|
||||||
// Teste si l'arbre a2 est vide
|
|
||||||
estArbreVide(a2);
|
|
||||||
|
|
||||||
// Vide l'arbre a1
|
|
||||||
viderArbre(&a1);
|
|
||||||
|
|
||||||
// Affiche l'arbre a1 en ordre croissant
|
|
||||||
afficherCroissant(a1);
|
|
||||||
|
|
||||||
// Affiche l'arbre a2 en ordre croissant
|
|
||||||
afficherCroissant(a2);
|
|
||||||
|
|
||||||
// Affiche l'arbre a2 en ordre décroissant
|
|
||||||
afficherDecroissant(a2);
|
|
||||||
|
|
||||||
// Vide l'arbre a2
|
|
||||||
viderArbre(&a2);
|
|
||||||
|
|
||||||
// Affiche à nouveau l'arbre a2 en ordre croissant
|
|
||||||
afficherCroissant(a2);
|
|
||||||
|
|
||||||
// Affiche à nouveau l'arbre a2 en ordre décroissant
|
|
||||||
afficherDecroissant(a2);
|
|
||||||
|
|
||||||
// Teste si l'arbre a2 est vide
|
|
||||||
estArbreVide(a2);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Fonction principale du programme.
|
|
||||||
*
|
|
||||||
* @return 0 en cas de succès.
|
|
||||||
*/
|
|
||||||
int main(void){
|
|
||||||
testAbr();
|
|
||||||
return 0;
|
|
||||||
}
|
|
@ -0,0 +1,62 @@
|
|||||||
|
#include "abr.h"
|
||||||
|
|
||||||
|
void testArbre(void){
|
||||||
|
Abr a = creerArbreVide();
|
||||||
|
Abr b = creerArbreVide();
|
||||||
|
Booleen resA, resB, resRechA;
|
||||||
|
if(a == NULL && b == NULL) printf("Arbre créée avec succès.\n");
|
||||||
|
else {
|
||||||
|
printf("Erreur lors de la création de l'arbre !\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
resA = estArbreVide(a);
|
||||||
|
resB = estArbreVide(b);
|
||||||
|
if(resA == TRUE && resB == TRUE) printf("Aucun Pb, les arbres sont bien vides.\n");
|
||||||
|
else printf("Pb, arbres non vide !\n");
|
||||||
|
|
||||||
|
insererEnFeuille(&a, 7);
|
||||||
|
insererEnFeuille(&a, 9);
|
||||||
|
insererEnFeuille(&a, 8);
|
||||||
|
insererEnFeuille(&a, 6);
|
||||||
|
|
||||||
|
resA = estArbreVide(a);
|
||||||
|
if(resA == TRUE) printf("Erreur, l'abre incrémenté est vide !\n");
|
||||||
|
else printf("Aucun pb.\n");
|
||||||
|
|
||||||
|
viderArbre(&a);
|
||||||
|
|
||||||
|
resA = estArbreVide(a);
|
||||||
|
if(resA == TRUE) printf("Tout fonctionne, l'arbre A est bien vidé.\n");
|
||||||
|
else printf("Pb, l'arbre a n'a pas été vidé correctement !\n");
|
||||||
|
|
||||||
|
insererEnFeuille(&a, 7);
|
||||||
|
insererEnFeuille(&a, 9);
|
||||||
|
insererEnFeuille(&a, 8);
|
||||||
|
insererEnFeuille(&a, 6);
|
||||||
|
insererEnFeuille(&a, 1);
|
||||||
|
insererEnFeuille(&a, 2);
|
||||||
|
insererEnFeuille(&a, 18);
|
||||||
|
insererEnFeuille(&a, 11);
|
||||||
|
|
||||||
|
// afficherCroissant(a);
|
||||||
|
// afficherDecroissant(a);
|
||||||
|
printf("\n\n");
|
||||||
|
afficherCouche(a);
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
int val1 = 3;
|
||||||
|
char arbreDeRecherche = 'a';
|
||||||
|
|
||||||
|
resRechA = rechercherVal(a, val1);
|
||||||
|
|
||||||
|
if(resRechA) printf("La valeur %d est bien dans l'arbre %c\n", val1, arbreDeRecherche);
|
||||||
|
else printf("La valeur %d n'est pas présente dans l'arbre %c\n", val1, arbreDeRecherche);
|
||||||
|
|
||||||
|
supprimerVal(&a, 2);
|
||||||
|
supprimerVal(&a, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void){
|
||||||
|
testArbre();
|
||||||
|
return 0;
|
||||||
|
}
|
Before Width: | Height: | Size: 676 B After Width: | Height: | Size: 676 B |
Before Width: | Height: | Size: 635 B After Width: | Height: | Size: 635 B |
Before Width: | Height: | Size: 132 B After Width: | Height: | Size: 132 B |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
Before Width: | Height: | Size: 15 KiB After Width: | Height: | Size: 15 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 3.2 KiB After Width: | Height: | Size: 3.2 KiB |
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 3.1 KiB |
Before Width: | Height: | Size: 582 B After Width: | Height: | Size: 582 B |
Before Width: | Height: | Size: 582 B After Width: | Height: | Size: 582 B |