summaryrefslogtreecommitdiff
path: root/structures/task5.cpp
blob: 72e1381c096f36b1d29f727cfb4848a44d5e74ef (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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;

}