summaryrefslogtreecommitdiff
path: root/structures/queue.h
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2021-02-10 23:06:37 +0400
committerAndrew <saintruler@gmail.com>2021-02-10 23:06:37 +0400
commit8090e4beb10133f5df865a219a87140b50324fda (patch)
treed3e5412c5e1c3eb3a747da9dea16ccdff6a54341 /structures/queue.h
parent43a261149b8bd3d811a330ff6cb6c1e774fd14d7 (diff)
Добавил решение 14 задачи
Diffstat (limited to 'structures/queue.h')
-rw-r--r--structures/queue.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/structures/queue.h b/structures/queue.h
new file mode 100644
index 0000000..368da01
--- /dev/null
+++ b/structures/queue.h
@@ -0,0 +1,33 @@
+#pragma once
+
+struct queue
+{
+ int inf;
+ queue *next;
+};
+
+void push(queue *&h, queue *&t, int x)
+{
+ queue *r = new queue;
+ r->inf = x;
+ r->next = NULL;
+
+ if (!h && !t)
+ h = t = r;
+ else
+ {
+ t->next = r;
+ t = r;
+ }
+}
+
+int pop(queue *&h, queue *&t)
+{
+ queue *r = h;
+ int i = h->inf;
+ h = h->next;
+
+ if (!h) t = NULL;
+ delete r;
+ return i;
+}