Guest User

Untitled

a guest
Jul 22nd, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct e{
  5.   int num;
  6.   struct e *fg, *fd;
  7. }Noeud;
  8.  
  9. typedef Noeud * Arbre;
  10.  
  11. void init(Arbre *P){
  12.   (*P)->fg=NULL;
  13.   (*P)->fd=NULL;
  14. }
  15.  
  16. void affich_Noeud (Arbre P){
  17.     if(P!=NULL){
  18.         printf("%d\n", P->num);
  19.         affich_Noeud (P->fg);
  20.         affich_Noeud (P->fd);
  21.     }
  22. }
  23.  
  24. Arbre ajout ( Arbre P, int x){
  25.    
  26.   if ( P==NULL){
  27.     Arbre nouv;
  28.     nouv=(Arbre)malloc(sizeof(Noeud));
  29.     init (&nouv);
  30.  
  31.     nouv->num=x;
  32.     return nouv;
  33.   }
  34.   else{
  35.     if(P->num =< x){
  36.         if(P->fg!=NULL)
  37.             return ajout(P->fg, x);
  38.         else{
  39.             Arbre nouv;
  40.             nouv=(Arbre)malloc(sizeof(Noeud));
  41.             init (&nouv);
  42.  
  43.             nouv->num=x;
  44.             P->fg=nouv;
  45.             return P;
  46.         }
  47.     }
  48.     else{
  49.         if(P->fd !=NULL)
  50.             return ajout(P->fd, x);
  51.         else{
  52.             Arbre nouv;
  53.             nouv=(Arbre)malloc(sizeof(Noeud));
  54.             init (&nouv);
  55.  
  56.             nouv->num=x;
  57.             P->fd=nouv;
  58.             return P;
  59.         }
  60.     }
  61.  }
  62. }
  63.  
  64. int main(int argc, char *argv[])
  65. {
  66.     Arbre P =NULL;
  67.     int i;
  68.    
  69.    
  70. }
Add Comment
Please, Sign In to add comment