Advertisement
Mohamed_AIT_RAMI

Untitled

Dec 18th, 2018
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. typedef struct
  5. {
  6.     int code;
  7.     char nom[20];
  8. }Adherent;
  9. typedef struct Liste
  10. {
  11.     Adherent donnee;
  12.     struct Liste *suiv;
  13. }Liste;
  14. Liste *new_element()
  15. {
  16.     Liste *ne;
  17.     ne=(Liste *)malloc(sizeof(Liste));
  18.     ne->suiv=NULL;
  19.     printf("donner le code de l'adherent\n");
  20.     scanf("%d",&ne->donnee.code);
  21.     getchar();
  22.      printf("donner le nom de l'adherent\n");
  23.      gets(ne->donnee.nom);
  24.      return ne;
  25.  
  26. }
  27. Liste *Insertion_Tete(Liste *T,Liste *ne)
  28. {
  29.     if(T==NULL)
  30.     {
  31.         T=ne;
  32.     }
  33.     else
  34. {
  35.  
  36.       ne->suiv=T;
  37.         T=ne;
  38.     }
  39.     return T;
  40. }
  41. Liste *Insertion_Queue(Liste *T,Liste *ne)
  42. {
  43.     Liste *p=T;
  44.     while(p->suiv!=NULL)
  45.     {
  46.         p=p->suiv;
  47.     }
  48.     p->suiv=ne;
  49.     return T;
  50. }
  51. void Afficher(Liste *T)
  52. {
  53.     Liste *p=T;
  54.     while(p!=NULL)
  55.     {   printf("le nom:%s le code:%d\n",p->donnee.nom,p->donnee.code);
  56.         p=p->suiv;
  57.     }
  58. }
  59. int Rechercher(int cd,Liste *T)
  60. {
  61.     Liste *p=T;
  62.     while(p!=NULL)
  63.     {
  64.         if(p->donnee.code==cd)
  65.         {
  66.            printf("le nom:%s le code:%d\n",p->donnee.nom,p->donnee.code);
  67.            return 1;
  68.         }
  69.         p=p->suiv;
  70.     }
  71.     printf("n'existe pas\n");
  72.     return 0;
  73. }
  74. void modification(Liste *T,int cd)
  75. {
  76.    char nom_nouv[20];
  77.     Liste *p=T;
  78.     while(p!=NULL)
  79.     {
  80.         if(p->donnee.code==cd)
  81.         {
  82.            printf("le nom:%s le code:%d\n",p->donnee.nom,p->donnee.code);
  83.            printf("le nouveau nom \n");
  84.            gets(nom_nouv);
  85.            strcpy(p->donnee.nom,nom_nouv);
  86.            return ;
  87.         }
  88.         p=p->suiv;
  89.     }
  90.     printf("n'existe pas\n");
  91.    
  92.    
  93. }
  94. Liste *Suppression(Liste *T,int cd)
  95. {
  96.     Liste *q=T,*p=T;
  97.    
  98.     while(p->donnee.code!=cd&&p!=NULL)
  99.     {
  100.         q=p;
  101.         p=p->suiv;
  102.     }
  103.     if(p==NULL)
  104.     {
  105.         printf("n'existe pas\n");
  106.     }
  107.    
  108.     else if(p->donnee.code==cd)
  109.        
  110.     {
  111.         if(p==T)
  112.     {
  113.        
  114.    
  115.         T=T->suiv;
  116.         p->suiv=NULL;
  117.         free(p);
  118.     }
  119.     else
  120.     {
  121.         q->suiv=p->suiv;
  122.        
  123.         p->suiv=NULL;
  124.         free(p);
  125.     }
  126.     }
  127.     return T;
  128. }
  129. int main()
  130. { int n=0;
  131.     Liste *T=NULL;
  132. int *p;
  133. walo(&n);
  134.     printf("%d!\n",n);
  135.     return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement