summaryrefslogtreecommitdiff
path: root/lib/queue.c
blob: 9a017414e480d509c3937f7e1c56196b8e58b26e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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);
  }
}