diff options
| author | Andrew Guschin <saintruler@gmail.com> | 2021-02-09 09:44:51 +0400 |
|---|---|---|
| committer | Andrew Guschin <saintruler@gmail.com> | 2021-02-09 09:44:51 +0400 |
| commit | 2f9aaa4bd1fc15aa7602eb1ea169ee01c626c737 (patch) | |
| tree | 6d3cb14b0a6589feac24475ec5363ba59c36e8ad /structures/task5.cpp | |
Initial commit
Diffstat (limited to 'structures/task5.cpp')
| -rw-r--r-- | structures/task5.cpp | 81 |
1 files changed, 81 insertions, 0 deletions
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; + +} |