37 lines
623 B
C
37 lines
623 B
C
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
|
||
|
typedef char* pile;
|
||
|
|
||
|
void push(pile* p, char c) {
|
||
|
p = (pile*)realloc(p, sizeof(*p) + sizeof(char));
|
||
|
(*p)[(sizeof(*p)/sizeof(char))-1] = c;
|
||
|
}
|
||
|
|
||
|
char pop(pile* p) {
|
||
|
char c = (*p)[(sizeof(*p)/sizeof(char))-1];
|
||
|
p = realloc(p, sizeof(*p) - sizeof(char));
|
||
|
return c;
|
||
|
}
|
||
|
|
||
|
int empty(pile p) {
|
||
|
return p[0] == 0;
|
||
|
}
|
||
|
|
||
|
char top(pile p) {
|
||
|
return p[(sizeof(p)/sizeof(char))-1];
|
||
|
}
|
||
|
|
||
|
void clear(pile* p) {
|
||
|
p = realloc(p, sizeof(char));
|
||
|
(*p)[0] = 0;
|
||
|
}
|
||
|
|
||
|
pile create() {
|
||
|
pile p = (pile)calloc(1, sizeof(char));
|
||
|
return p;
|
||
|
}
|
||
|
|
||
|
pile destroy(pile* p) {
|
||
|
free(p);
|
||
|
}
|