DEV/DEV1.1/TP15/file.c

37 lines
455 B
C

#include <stdio.h>
#include <stdlib.h>
struct pile{
char val;
struct pile *suite;
};
typedef struct pile pile;
int empty(pile* p){
return p==NULL;
}
void push(pile **p, char v){
pile *new=malloc(sizeof(pile));
new->val=v;
new->suite=*p;
*p=new;
}
char pop(pile **p){
char v=(*p)->val;
pile *temp=*p;
*p=(*p)->suite;
free(temp);
return v;
}
void clear(pile **p){
while(!empty(*p)){
pop(p);
}
}
char top(pile **p){
return (*p)->val;
}