Mise à jour de 'DEV1.1/TP15/file.c'

This commit is contained in:
Simon SAYE BABU 2023-01-11 14:17:24 +01:00
parent e4498c21e7
commit bfdbf7a373

View File

@ -1,56 +1,37 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
struct pile struct pile{
{ char val;
int tete; struct pile *suite;
char ple[10];
}; };
typedef struct pile pile; typedef struct pile pile;
int empty(pile *p) int empty(pile* p){
{ return p==NULL;
if(p==NULL)
{
return 1;
}
return p->tete==0;
} }
char pop(pile **p) void push(pile **p, char v){
{ pile *new=malloc(sizeof(pile));
(*p)->tete--; new->val=v;
return (*p)->ple[(*p)->tete]; new->suite=*p;
*p=new;
} }
void push(pile **p,char v) char pop(pile **p){
{ char v=(*p)->val;
if (*p==NULL) pile *temp=*p;
{ *p=(*p)->suite;
pile *new=malloc(sizeof(pile)); free(temp);
new->tete=0; return v;
*p=new;
push(p,v);
}else
{
(*p)->ple[(*p)->tete]=v;
(*p)->tete++;
}
} }
char top(pile **p) void clear(pile **p){
{ while(!empty(*p)){
char temp = pop(p);
push(p,temp);
return temp;
}
void clear(pile **p)
{
while(!empty((*p)))
{
pop(p); pop(p);
} }
}
char top(pile **p){
return (*p)->val;
} }