DEV/DEV1.1/TP15/pile.c
2023-01-04 15:31:14 +01:00

56 lines
568 B
C

#include <stdio.h>
#include <stdlib.h>
struct pile
{
int tete;
char ple[10];
};
typedef struct pile pile;
int empty(pile *p)
{
if(p==NULL)
{
return 1;
}
return p->tete==0;
}
char pop(pile **p)
{
(*p)->tete--;
return (*p)->ple[(*p)->tete];
}
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 top(pile **p)
{
char temp = pop(p);
push(p,temp);
return temp;
}
void clear(pile **p)
{
while(!empty((*p)))
{
pop(p);
}
}