From a7a0646a34a1430568ec5cb22534f24c886d127b Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 10 Feb 2021 23:15:28 +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=2018=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/task18.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 structures/task18.cpp (limited to 'structures/task18.cpp') diff --git a/structures/task18.cpp b/structures/task18.cpp new file mode 100644 index 0000000..f78c9ba --- /dev/null +++ b/structures/task18.cpp @@ -0,0 +1,48 @@ +#include +#include "queue.h" + +using namespace std; + +void result(queue *&h, queue *&t, queue *&hr, queue *&tr) +{ + int prev; + prev = pop(h, t); + push(hr, tr, prev); + + while (h) + { + int cur = pop(h, t); + if (cur != prev) + { + prev = cur; + push(hr, tr, cur); + } + } +} + +int main() +{ + int n; + cout << "n = "; + cin >> n; + + queue *head = NULL; + queue *tail = NULL; + char x; + for (int i = 0; i < n; i++) + { + cin >> x; + push(head, tail, int(x)); + } + + queue *head_res = NULL; + queue *tail_res = NULL; + + result(head, tail, head_res, tail_res); + while (head_res) + cout << char(pop(head_res, tail_res)) << " "; + cout << endl; + + return 0; + +} -- cgit v1.2.3