2023-01-04 15:30:40 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
struct pile{
|
|
|
|
char val;
|
|
|
|
struct pile *suiv;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct pile pile;
|
|
|
|
|
|
|
|
int empty (pile *p){
|
|
|
|
return p->suiv==NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void push (pile **p,char v){
|
2023-01-11 15:18:44 +01:00
|
|
|
pile *nouveau=malloc(sizeof(pile));
|
|
|
|
nouveau->val=v;
|
|
|
|
nouveau->suiv=*p;
|
|
|
|
*p=nouveau;
|
2023-01-04 15:30:40 +01:00
|
|
|
}
|
|
|
|
|
2023-01-11 15:18:44 +01:00
|
|
|
char pop(pile **p) {
|
|
|
|
int valDepiler;
|
|
|
|
pile *temp=malloc(sizeof(pile));
|
|
|
|
temp = (*p)->suiv;
|
|
|
|
valDepiler = (*p)->val;
|
|
|
|
free(*p);
|
|
|
|
*p = temp;
|
|
|
|
return valDepiler;
|
2023-01-04 15:30:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(){
|
|
|
|
char c=0;
|
2023-01-11 15:18:44 +01:00
|
|
|
pile *p=malloc(sizeof(pile));
|
2023-01-04 15:30:40 +01:00
|
|
|
|
|
|
|
printf("La pile attend vos ordres\n");
|
|
|
|
while (c!='q'){
|
|
|
|
scanf("%c",&c);
|
|
|
|
if (c=='+'){
|
|
|
|
scanf("%c",&c);
|
|
|
|
push((&p),c);
|
|
|
|
printf("Le caractère %c a été ajouté\n",c);
|
2023-01-11 15:18:44 +01:00
|
|
|
} if(c=='-'){
|
|
|
|
if (empty(p)==1){
|
|
|
|
printf("La pile est vide !\n");
|
|
|
|
}else{
|
|
|
|
c=pop(&p);
|
|
|
|
printf("Le caractère %c a été supprimé\n",c);
|
2023-01-04 15:30:40 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("Au revoir\n");
|
|
|
|
return 0;
|
|
|
|
}
|