From f7a21799194f6626994195302ac95449158bdcd9 Mon Sep 17 00:00:00 2001 From: Jaron Kent-Dobias Date: Thu, 25 May 2017 13:26:38 -0400 Subject: started wolff code in new repository --- lib/queue.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/queue.c (limited to 'lib/queue.c') diff --git a/lib/queue.c b/lib/queue.c new file mode 100644 index 0000000..9a01741 --- /dev/null +++ b/lib/queue.c @@ -0,0 +1,32 @@ + +#include "wolff.h" + +void stack_push(ll_t **q, uint32_t x) { + ll_t *nq = malloc(sizeof(ll_t)); + nq->x = x; + nq->next = *q; + + *q = nq; +} + +uint32_t stack_pop(ll_t **q) { + ll_t *old_q = *q; + + *q = old_q->next; + uint32_t x = old_q->x; + + free(old_q); + + return x; +} + +bool stack_contains(const ll_t *q, uint32_t x) { + if (q == NULL) { + return false; + } else if (q->x == x) { + return true; + } else { + return stack_contains(q->next, x); + } +} + -- cgit v1.2.3-70-g09d2