aboutsummaryrefslogtreecommitdiff
path: root/src/lib/q.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/q.c')
-rw-r--r--src/lib/q.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/lib/q.c b/src/lib/q.c
new file mode 100644
index 0000000..e40fee8
--- /dev/null
+++ b/src/lib/q.c
@@ -0,0 +1,38 @@
+#include "../lib/q.h"
+#include "../lib/mem.h"
+
+struct Q_base* newq()
+{
+ struct Q_base* q = (struct Q_base*)malloc(sizeof(struct Q_base));
+ q->next = 0;
+ q->last = 0;
+ return q;
+}
+
+void pushq(struct Q_base* qb, void* val)
+{
+ struct Q* n = (struct Q*)malloc(sizeof(struct Q));
+ n->next = 0;
+ n->data = val;
+ if (qb->last != 0)
+ qb->last->next = n;
+ else {
+ qb->next = n;
+ }
+ qb->last = n;
+}
+
+void popq(struct Q_base* qb)
+{
+ if (qb->next == 0)
+ return;
+ if (qb->next == qb->last) {
+ free(qb->next);
+ qb->next = 0;
+ qb->last = 0;
+ return;
+ }
+ struct Q* t = qb->next;
+ qb->next = qb->next->next;
+ free(t);
+}