meryemnamiq

LIFO

Aug 29th, 2020
1,112
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. struct pile{
  5.     int num;
  6.     struct pile* suiv;
  7. };
  8. typedef struct pile* Pile;
  9.  
  10.  
  11. int pileVide(Pile p){
  12.     return p==NULL;
  13. }
  14.  
  15. int pilePlein(Pile p){
  16.     return !pileVide(p);
  17. }
  18.  
  19. void empliler(Pile *p,int x){
  20.     Pile pp;
  21.     pp=malloc(sizeof(struct pile));
  22.     pp->num=x;
  23.     pp->suiv=(*p);
  24.     (*p)=pp;
  25. }
  26.  
  27. int premier(Pile p){
  28.     return p->num;
  29. }
  30.  
  31. int depiler(Pile *p){
  32.     Pile pp;int s;
  33.     pp=(*p);
  34.     s=pp->num;
  35.     (*p)=(*p)->suiv;
  36.     free(pp);
  37.     return s;  
  38. }
  39.  
  40. void vider(Pile *p){
  41.     while(pilePlein(*p)){
  42.         int s=depiler(&(*p));
  43.     }
  44. }
  45.  
  46. main(){
  47.     Pile p;
  48.     empliler(&p,1);
  49.     empliler(&p,2);
  50.     empliler(&p,3);
  51.     empliler(&p,4);
  52.    
  53.     printf("\n_____%d",depiler(&p));
  54.     printf("\n_____%d",depiler(&p));
  55.    
  56.     printf("\n__p__%d",pilePlein(p));
  57.     vider(&p);
  58.     printf("\n__p__%d",pilePlein(p));
  59.    
  60. }
RAW Paste Data