summaryrefslogtreecommitdiff
path: root/structures/task18.cpp
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2021-02-10 23:15:28 +0400
committerAndrew <saintruler@gmail.com>2021-02-10 23:15:28 +0400
commita7a0646a34a1430568ec5cb22534f24c886d127b (patch)
tree081059067e69c73960f1b92e76680f7a24d4b047 /structures/task18.cpp
parent8090e4beb10133f5df865a219a87140b50324fda (diff)
Добавил решение 18 задачи
Diffstat (limited to 'structures/task18.cpp')
-rw-r--r--structures/task18.cpp48
1 files changed, 48 insertions, 0 deletions
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 <iostream>
+#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;
+
+}