summaryrefslogtreecommitdiff
path: root/list/task7.cpp
blob: 4068a6f9f41a5704b0e5ca8eb2167930e94ec70e (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
#include <iostream>
#include "list.h"

using namespace std;

void solve(list *&h, list *&t, int x)
{
    int size = 0;
    list *cur = h;
    while (cur) 
    {
        size++;
        cur = cur->next;
    }

    cur = h;
    for (int i = 0; i < size; i++)
    {
        if (cur->inf >= x)
        {
            push(h, t, cur->inf);
            list *tmp = cur;
            cur = cur->next;
            del_node(h, t, tmp);
        }
        else 
        {
            cur = cur->next;
        }
    }
}

int main()
{
    int n;
    cout << "n = ";
    cin >> n;

    int x;
    cout << "x = ";
    cin >> x;

    list *head = NULL;
    list *tail = NULL;
    int t;
    for (int i = 0; i < n; i++)
    {
        cin >> t;
        push(head, tail, t);
    }

    solve(head, tail, x);
    print(head, tail);
    cout << endl;

    return 0;

}