59 lines
1.1 KiB
C
59 lines
1.1 KiB
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
struct maillon_s{
|
||
|
char valeur;
|
||
|
struct maillon_s* suivant;
|
||
|
};
|
||
|
|
||
|
typedef struct maillon_s maillon;
|
||
|
|
||
|
void push(Pile* pile, int element) {
|
||
|
Maillon* nouveauMaillon = (Maillon*)malloc(sizeof(Maillon));
|
||
|
if (nouveauMaillon == NULL) {
|
||
|
|
||
|
fprintf(stderr, "Erreur d'allocation mémoire.\n");
|
||
|
|
||
|
exit(EXIT_FAILURE);
|
||
|
|
||
|
}
|
||
|
nouveauMaillon->donnee = element;
|
||
|
nouveauMaillon->suivant = pile->sommet;
|
||
|
pile->sommet = nouveauMaillon;
|
||
|
}
|
||
|
|
||
|
int pop(Pile* pile) {
|
||
|
if (!pile_empty(pile)) {
|
||
|
Maillon* maillonPop = pile->sommet;
|
||
|
int donneePop = maillonPop->donnee;
|
||
|
pile->sommet = maillonPop->suivant;
|
||
|
free(maillonPop);
|
||
|
return donneePop;
|
||
|
} else {
|
||
|
fprintf(stderr, "La pile est vide.\n");
|
||
|
exit(EXIT_FAILURE);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
int empty(const Pile* pile) {
|
||
|
return (pile->sommet == NULL);
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
void push(pile* p, char new){
|
||
|
maillon* m = (maillon) malloc(sizeof(maillon));
|
||
|
m->valeur = nouveaux;
|
||
|
m->suivant = *p;
|
||
|
*p = m;
|
||
|
}
|
||
|
|
||
|
char pop(pile* p){
|
||
|
maillon* m = (*p)-> valeur;
|
||
|
pile* tp = *p;
|
||
|
|
||
|
}
|
||
|
|
||
|
int empty(pile* p){
|
||
|
return p == NULL;
|
||
|
}
|
||
|
*/
|