DEV_BUT1/DEV1.1S/TPPILE/chainee_tables.c
2023-02-08 11:18:16 +01:00

47 lines
730 B
C

#include <stdio.h>
#include <stdlib.h>
struct pile_ {
char* tab;
int size;
};
typedef struct pile_ pile;
void push(pile* p, char c) {
(p->tab)[p->size] = c;
p->size++;
p->tab = realloc(p->tab, (p->size)+1);
}
char pop(pile* p) {
char c = (p->tab)[p->size-1];
p->size--;
p->tab = realloc(p->tab, (p->size)+1);
return c;
}
int empty(pile p) {
return p.size == 0;
}
char top(pile p) {
return (p.tab)[(p.size) - 1];
}
void clear(pile* p) {
free(p->tab);
p->tab = calloc(1, sizeof(int));
p->size = 0;
}
pile create() {
pile* p = (calloc(1, sizeof(pile)));
p->tab = calloc(1, sizeof(char));
p->size = 0;
return *p;
}
pile destroy(pile* p) {
free(p);
}