#include #include struct TNoeud { int val; struct TNoeud *FG,*FD; }; void Ajouter(struct TNoeud **R,int x) { struct TNoeud *N1,*N; N=*R; if(N==NULL) { N=(struct TNoeud *)malloc(sizeof(struct TNoeud)); N->FG=NULL; N->FD=NULL; N->val=x; *R=N; } else { if(N->val==x) {printf("Cette val existe déjà");} if(N->val>x) { if(N->FG==NULL) { N1=(struct TNoeud *)malloc(sizeof(struct TNoeud)); N1->FG=NULL; N1->FD=NULL; N1->val=x; N->FG=N1; } else Ajouter(&N->FG,x); } if(N->valFD==NULL) { N1=(struct TNoeud *)malloc(sizeof(struct TNoeud)); N1->FG=NULL; N1->FD=NULL; N1->val=x; N->FD=N1; } else Ajouter(&N->FD,x); } } } void PPPrefixe(struct TNoeud *R) { if (R!=NULL) { printf("%d,",R->val); PPPrefixe(R->FG); PPPrefixe(R->FD); } } void PPInfixe(struct TNoeud *R) { if (R!=NULL) { PPInfixe(R->FG); printf("%d,",R->val); PPInfixe(R->FD); } } int main() { printf("======= TP arbres =======\n"); struct TNoeud *Racine=NULL; Ajouter(&Racine,10); Ajouter(&Racine,5); Ajouter(&Racine,15); Ajouter(&Racine,3); Ajouter(&Racine,7); Ajouter(&Racine,12); Ajouter(&Racine,20); PPPrefixe(Racine); printf("\n"); PPInfixe(Racine); return 0; }