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){
{
(*p)->tete--;
return (*p)->ple[(*p)->tete];
}
void push(pile **p,char v)
{
if (*p==NULL)
{
pile *new=malloc(sizeof(pile)); pile *new=malloc(sizeof(pile));
new->tete=0; new->val=v;
new->suite=*p;
*p=new; *p=new;
push(p,v);
}else
{
(*p)->ple[(*p)->tete]=v;
(*p)->tete++;
}
} }
char top(pile **p) char pop(pile **p){
{ char v=(*p)->val;
char temp = pop(p); pile *temp=*p;
push(p,temp); *p=(*p)->suite;
return temp; free(temp);
return v;
} }
void clear(pile **p) void clear(pile **p){
{ while(!empty(*p)){
while(!empty((*p)))
{
pop(p); pop(p);
} }
} }
char top(pile **p){
return (*p)->val;
}