diff options
author | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-02-02 18:33:22 -0500 |
---|---|---|
committer | Jaron Kent-Dobias <jaron@kent-dobias.com> | 2018-02-02 18:33:22 -0500 |
commit | 2af9351db3aa97da9b0d3f23d53a593bc96c8a8e (patch) | |
tree | 684dfccba8d295c42ef6e2e070c8d6caca45f590 /lib/stack.c | |
parent | 181db84a8ffb26e436a43bb268fe5ef060206e66 (diff) | |
download | c++-2af9351db3aa97da9b0d3f23d53a593bc96c8a8e.tar.gz c++-2af9351db3aa97da9b0d3f23d53a593bc96c8a8e.tar.bz2 c++-2af9351db3aa97da9b0d3f23d53a593bc96c8a8e.zip |
does potts now, no external libraries
Diffstat (limited to 'lib/stack.c')
-rw-r--r-- | lib/stack.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/stack.c b/lib/stack.c new file mode 100644 index 0000000..9fde1e6 --- /dev/null +++ b/lib/stack.c @@ -0,0 +1,41 @@ + +#include "stack.h" + +void stack_push(ll_t **q, v_t x) { + ll_t *nq = malloc(sizeof(ll_t)); + nq->x = x; + nq->next = *q; + + *q = nq; +} + +void stack_push_d(dll_t **q, double x) { + dll_t *nq = malloc(sizeof(dll_t)); + nq->x = x; + nq->next = *q; + + *q = nq; +} + +v_t stack_pop(ll_t **q) { + ll_t *old_q = *q; + + *q = old_q->next; + v_t x = old_q->x; + + free(old_q); + + return x; +} + +double stack_pop_d(dll_t **q) { + dll_t *old_q = *q; + + *q = old_q->next; + double x = old_q->x; + + free(old_q); + + return x; +} + |