summaryrefslogtreecommitdiff
path: root/structures/task5.cpp
blob: 56bcb1703b511716366df9a0be6eace24b2ccc2a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include "stack.h"

using namespace std;

void solve(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);
    }

    h = 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);

    solve(head);
    while (head)
        cout << char(pop(head)) << " ";
    cout << endl;

    return 0;

}