mp2i-info/tp7/exo7.c
2026-01-15 21:14:31 +01:00

22 lines
432 B
C

#include <stdbool.h>
#include <stdlib.h>
// Pile with size at index 0
int* creer_pileb(int capacite) {
int* b = malloc((capacite+1)*sizeof(int));
b[0] = 0;
return b;
}
// User must make sure that the size isn't bigger than capacity
void empiler_pileb(int* p, int x) {
p[p[0]+1] = x;
p[0]++;
}
int depiler_pileb(int* p) {
p[0]--;
return p[p[0]+1];
}
bool est_vide_pileb(int* p) {
return p[0] <= 0;
}