From 8090e4beb10133f5df865a219a87140b50324fda Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 10 Feb 2021 23:06:37 +0400 Subject: =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D1=80?= =?UTF-8?q?=D0=B5=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=2014=20=D0=B7=D0=B0=D0=B4?= =?UTF-8?q?=D0=B0=D1=87=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- structures/queue.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 structures/queue.h (limited to 'structures/queue.h') 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; +} -- cgit v1.2.3