From bfdbf7a3733fb8a2905be4612b3ed219aa56d189 Mon Sep 17 00:00:00 2001 From: Simon Saye Babu Date: Wed, 11 Jan 2023 14:17:24 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'DEV1.1/TP15/file.c?= =?UTF-8?q?'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DEV1.1/TP15/file.c | 63 ++++++++++++++++------------------------------ 1 file changed, 22 insertions(+), 41 deletions(-) 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