summaryrefslogtreecommitdiff
path: root/lib/queue.c
diff options
context:
space:
mode:
authorJaron Kent-Dobias <jaron@kent-dobias.com>2017-05-25 13:26:38 -0400
committerJaron Kent-Dobias <jaron@kent-dobias.com>2017-05-25 13:26:38 -0400
commitf7a21799194f6626994195302ac95449158bdcd9 (patch)
tree1b65f643f239f8abc8de015fe660486b11b3071e /lib/queue.c
downloadc++-f7a21799194f6626994195302ac95449158bdcd9.tar.gz
c++-f7a21799194f6626994195302ac95449158bdcd9.tar.bz2
c++-f7a21799194f6626994195302ac95449158bdcd9.zip
started wolff code in new repository
Diffstat (limited to 'lib/queue.c')
-rw-r--r--lib/queue.c32
1 files changed, 32 insertions, 0 deletions
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);
+ }
+}
+