summaryrefslogtreecommitdiff
path: root/structures/task14.cpp
blob: fcd9d63692508e2e75a4422c36bc680b32d5f1e5 (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
#include <iostream>
#include "queue.h"

using namespace std;

void result(queue *&h, queue *&t, queue *&hr, queue *&tr)
{
    while (h)
    {
        int el = char(pop(h, t));
        if (  '0' <= el && el <= '9'
           || 'a' <= el && el <= 'z' 
           || 'A' <= el && el <= 'Z' )
        {
            push(hr, tr, int(el));
        }
    }
}

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;

}