diff --git a/DEV1.1/TP15/file.c b/DEV1.1/TP15/file.c index 16da646..f049fc8 100644 --- a/DEV1.1/TP15/file.c +++ b/DEV1.1/TP15/file.c @@ -1,56 +1,37 @@ #include #include -#include -struct pile -{ - int tete; - char ple[10]; +struct pile{ + char val; + struct pile *suite; }; - typedef struct pile pile; -int empty(pile *p) -{ - if(p==NULL) - { - return 1; - } - return p->tete==0; +int empty(pile* p){ + return p==NULL; } -char pop(pile **p) -{ - (*p)->tete--; - return (*p)->ple[(*p)->tete]; +void push(pile **p, char v){ + pile *new=malloc(sizeof(pile)); + new->val=v; + new->suite=*p; + *p=new; } -void push(pile **p,char v) -{ - if (*p==NULL) - { - pile *new=malloc(sizeof(pile)); - new->tete=0; - *p=new; - push(p,v); - }else - { - (*p)->ple[(*p)->tete]=v; - (*p)->tete++; - } +char pop(pile **p){ + char v=(*p)->val; + pile *temp=*p; + *p=(*p)->suite; + free(temp); + return v; } -char top(pile **p) -{ - char temp = pop(p); - push(p,temp); - return temp; -} - -void clear(pile **p) -{ - while(!empty((*p))) - { +void clear(pile **p){ + while(!empty(*p)){ pop(p); } +} + +char top(pile **p){ + return (*p)->val; } \ No newline at end of file