Advertisement
Mohamed_AIT_RAMI

SDD - Last session

Dec 20th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. //Les prototypes
  2. arbre *creerFeuille(int x);
  3. arbre *ajouter(int x,arbre *arb);
  4. void explorer(arbre *arb);
  5. int recherche(int x,arbre *arb);
  6. arbre *supprimer(int x,arbre **arb);
  7. int profondeur(arbre *arb);
  8.  
  9.  
  10. //Les fonctions
  11. arbre* creerFeuille(char* x) {
  12.     arbre *feuille =malloc(arbre);
  13.     if (feuille !=NULL) {
  14.         feuille->cle=x;
  15.         feuille->gauche=NULL;
  16.         feuille->droit=NULL;
  17.         return feuille;
  18.     }
  19. }
  20.  
  21. arbre *ajouter(char x, arbre *arb) {
  22.     if (arb==NULL) {
  23.         arb=creerFeuille(x);
  24.     }
  25.     else {
  26.         if(x<arb->cle)
  27.             arb->gauche=ajouter(x,arb->gauche);
  28.         else
  29.             arb->droit=ajouter(x,arb->droit);
  30.     }
  31.     return arb;
  32. }
  33.  
  34. void explorer(arbre *arb) {
  35.     if (arb!=NULL) {
  36.         explorer(arb->gauche);
  37.         printf("%d\t",arb->cle);
  38.         explorer(arb->droit);
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement