1 #include <stdlib.h> // malloc, realloc
3 #include "include/cstack.h"
5 cstack_t *cstack_init() {
6 cstack_t *stack = malloc(sizeof(cstack_t));
7 stack->content = (void*)0;
8 stack->alloc = stack->size = 0;
10 stack->push = cstack_push;
11 stack->pop = cstack_pop;
12 stack->top = cstack_top;
13 stack->empty = cstack_empty;
14 stack->delete = cstack_delete;
18 void cstack_push(cstack_t *self, char c) {
19 if(self->size + sizeof(c) > self->alloc) {
20 self->alloc += (sizeof(char));
21 self->content = realloc(self->content, self->alloc);
23 self->content[++self->head] = c;
24 self->size += (sizeof(char));
27 char cstack_pop(cstack_t *self) {
28 self->size -= (sizeof(char));
29 return self->content[self->head--];
32 char cstack_top(cstack_t *self) {
33 return self->content[self->head];
36 int cstack_empty(cstack_t *self) {
37 return self->head == -1;
40 void cstack_delete(cstack_t *self) {