summaryrefslogtreecommitdiff
path: root/structures
diff options
context:
space:
mode:
authorAndrew Guschin <saintruler@gmail.com>2021-02-09 09:44:51 +0400
committerAndrew Guschin <saintruler@gmail.com>2021-02-09 09:44:51 +0400
commit2f9aaa4bd1fc15aa7602eb1ea169ee01c626c737 (patch)
tree6d3cb14b0a6589feac24475ec5363ba59c36e8ad /structures
Initial commit
Diffstat (limited to 'structures')
-rwxr-xr-xstructures/run.sh7
-rw-r--r--structures/task5.cpp81
2 files changed, 88 insertions, 0 deletions
diff --git a/structures/run.sh b/structures/run.sh
new file mode 100755
index 0000000..f076a51
--- /dev/null
+++ b/structures/run.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+name="${1%%.*}"
+g++ -Wall -o $name.out $name.cpp
+./$name.out
+rm $name.out
+
diff --git a/structures/task5.cpp b/structures/task5.cpp
new file mode 100644
index 0000000..72e1381
--- /dev/null
+++ b/structures/task5.cpp
@@ -0,0 +1,81 @@
+#include <iostream>
+using namespace std;
+
+struct stack
+{
+ int inf;
+ stack *next;
+};
+
+void push(stack *&h, int x)
+{
+ stack *r = new stack;
+ r->inf = x;
+ r->next = h;
+ h = r;
+}
+
+int pop(stack *&h)
+{
+ int i = h->inf;
+ stack *r = h;
+ h = h->next;
+ delete r;
+ return i;
+}
+
+void reverse(stack *&h)
+{
+ stack *head1 = NULL;
+ while (h)
+ push(head1, pop(h));
+ h = head1;
+}
+
+stack *result(stack *&h)
+{
+ stack *tmp = NULL;
+ stack *res = NULL;
+
+ while (h)
+ {
+ int c;
+ c = pop(h);
+ if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
+ push(tmp, c);
+ else
+ push(res, c);
+ }
+
+ reverse(res);
+ while (tmp)
+ {
+ int elem;
+ elem = pop(tmp);
+ push(res, elem);
+ }
+
+ return res;
+}
+
+int main()
+{
+ int n;
+ cout << "n = ";
+ cin >> n;
+ stack *head = NULL;
+ char x;
+ for (int i = 0; i < n; i++)
+ {
+ cin >> x;
+ push(head, int(x));
+ }
+ reverse(head);
+ stack *res = result(head);
+ while (res)
+ cout << char(pop(res)) << " ";
+ cout << endl;
+
+ return 0;
+
+}