DEV/DEV1.1/TP29/test.c
Simoes Lukas 59f7eead89 A
2025-01-07 15:07:12 +01:00

50 lines
686 B
C

# include <stdio.h>
# include <stdlib.h>
struct maillon_s {
char valeur;
struct maillon_s* suivant;
};
typedef struct maillon_s pile;
void push(pile* p, char c) {
pile* s = p;
s = (pile*) malloc(sizeof(pile));
p->valeur = c;
p->suivant = s;
}
int empty(pile* p) {
return (p == NULL);
}
char pop(pile* p) {
if (!empty) {
pile* s = p;
free(p);
return s->valeur;
}
}
void affiche_pile(pile* p) {
pile* s;
for (s = p; s->suivant != NULL; s = s->suivant) {
printf("| %c |\n", s->valeur);
}
printf("-----\n");
}
int main(void) {
pile* p;
push(p, 'A');
affiche_pile(p);
push(p, 'B');
affiche_pile(p);
push(p, 'C');
affiche_pile(p);
return EXIT_SUCCESS;
}