1 #if !defined( CSTACK_H )
5 * An implementation of a char stack in heap memory.
6 * Copyright (C) 2014 Michael Goehler
8 * This file is part of mdp.
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * struct: cstack_t which defines char stack type in heap memory
26 * function: cstack_init to intialize struct of type cstack_t
27 * function: cstack_t->push to add one char on top if the stack
28 * function: cstack_t->pop to remove the top char from the stack
29 * function: cstack_t->top to test if the top char is a given char
30 * function: cstack_t->empty to test if the stack is empty
31 * function: cstack_t->delete to free the allocated memory
34 * cstack_t *p = cstack_init();
36 * printf("%c\n", (p->pop)(p));
43 typedef struct _cstack_t {
48 void (*push)(struct _cstack_t *self, char c);
49 char (*pop)(struct _cstack_t *self);
50 bool (*top)(struct _cstack_t *self, char c);
51 bool (*empty)(struct _cstack_t *self);
52 void (*delete)(struct _cstack_t *self);
55 cstack_t *cstack_init();
56 void cstack_push(cstack_t *self, char c);
57 char cstack_pop(cstack_t *self);
58 bool cstack_top(cstack_t *self, char c);
59 bool cstack_empty(cstack_t *self);
60 void cstack_delete(cstack_t *self);
62 #endif // !defined( CSTACK_H )