Académique Documents
Professionnel Documents
Culture Documents
h>
#include <stdlib.h>
typedef
struct Noeud{
int valeur;
}* Arbre;
void creation2(Arbre R)
{
int x;
printf("entre un nombre");
scanf("%d",&x);
if(x==-1)
{
R=NULL;
else{
Arbre R=malloc(sizeof(Arbre));
R->valeur=x;
creation2(R->gauche);
creation2(R->droite);
else if(R->valeur==x)
return R;
return findadresse(R->droite,x);
{
Arbre nod=malloc(sizeof(Arbre));
nod->valeur=valfis;
nod->gauche=NULL;
nod->droite=NULL;
if(pere == NULL)
else if (position==0)
pere->gauche = nod;
else if (position==1)
pere->droite = nod;
{
if (R==NULL) return 0;
else if (R->valeur<x)
if(R->valeur<x )
{
printf("%d ..",R->valeur);
calculNbrVinfABR(R->gauche,x);
{
if (R==NULL) return 0;
while(x<R->valeur)
{ if (R->valeur==x)
return 1+NbrOCCABR(R->gauche,x)+NbrOCCABR(R->droite,x);
break;
if (R->valeur==x)
return 1+NbrOCCABR(R->droite,x)+NbrOCCABR(R->gauche,x);
void affichage(Arbre R)
{
if(R!=NULL){
printf("%d - ",R->valeur);
affichage(R->gauche);
affichage(R->droite);
}
{
if(R==NULL) return NULL;
else if(R->valeur==x)
R=NULL;
return suppression(R->droite,x);
void main()
{
int choix=1;
int x;
int X;
int V;
int nbr;
int valfis,position;
Arbre R=(Arbre)malloc(sizeof(Arbre));
R->valeur=4;
R->gauche=(Arbre)malloc(sizeof(Arbre));
R->gauche->valeur=2;
R->gauche->gauche=(Arbre)malloc(sizeof(Arbre));
R->gauche->gauche->valeur=1;
R->gauche->gauche->gauche=NULL;
R->gauche->gauche->droite=NULL;
R->gauche->droite=(Arbre)malloc(sizeof(Arbre));
R->gauche->droite->valeur=3;
R->gauche->droite->gauche=NULL;
R->gauche->droite->droite=NULL;
R->droite=(Arbre)malloc(sizeof(Arbre));
R->droite->valeur=5;
R->droite->droite=NULL;
R->droite->gauche=NULL;
printf(" DEVOIR N°2 Atil Nour El houda G2 \n 1 pour affichage de l'arbre \n 2 pour
EXO N 2-1 (find adresse) \n
3 pour EXO N 2-2 (ajoute noeud) \n 4 pour EXO N 7 (calculer nbr neuod < X) \n
5 pour EXO N 13 (imprime les valeur < X) \n 6 pour EXO N 14 (occurence d'un
ABR) \n
7 pour suppresion Heap Min \n ");
while(choix!=0)
{ printf(" \n");
scanf("%d",&choix);
if(choix<1 || choix>10)
{ printf("errooor");
}
else
{
switch(choix)
case 1:
affichage(R);
break;
case 2:
scanf("%d",&x);
findadresse(R,x);
break;
case 3:
scanf("%d",&valfis);
scanf("%d",&position);
ajouter(R,valfis,position);
break;
case 4:
scanf("%d",&x);
nbr=calculNbrVinf(R,x);
break;
case 5:
scanf("%d",&x);
calculNbrVinfABR(R,x);
break;
case 6:
nbr=NbrOCCABR(R,x);
break;
case 7:
scanf("%d",&x);
suppression(R,x);
break;