2023-01-11 14:14:52 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2023-01-11 14:17:24 +01:00
|
|
|
struct pile{
|
|
|
|
char val;
|
|
|
|
struct pile *suite;
|
2023-01-11 14:14:52 +01:00
|
|
|
};
|
|
|
|
typedef struct pile pile;
|
|
|
|
|
2023-01-11 14:17:24 +01:00
|
|
|
int empty(pile* p){
|
|
|
|
return p==NULL;
|
2023-01-11 14:14:52 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:17:24 +01:00
|
|
|
void push(pile **p, char v){
|
|
|
|
pile *new=malloc(sizeof(pile));
|
|
|
|
new->val=v;
|
|
|
|
new->suite=*p;
|
|
|
|
*p=new;
|
2023-01-11 14:14:52 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:17:24 +01:00
|
|
|
char pop(pile **p){
|
|
|
|
char v=(*p)->val;
|
|
|
|
pile *temp=*p;
|
|
|
|
*p=(*p)->suite;
|
|
|
|
free(temp);
|
|
|
|
return v;
|
2023-01-11 14:14:52 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 14:17:24 +01:00
|
|
|
void clear(pile **p){
|
|
|
|
while(!empty(*p)){
|
2023-01-11 14:14:52 +01:00
|
|
|
pop(p);
|
|
|
|
}
|
2023-01-11 14:17:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
char top(pile **p){
|
|
|
|
return (*p)->val;
|
2023-01-11 14:14:52 +01:00
|
|
|
}
|