-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmid-exam-code-5.cpp
More file actions
54 lines (47 loc) · 873 Bytes
/
Copy pathmid-exam-code-5.cpp
File metadata and controls
54 lines (47 loc) · 873 Bytes
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
#include <bits/stdc++.h>
using namespace std;
void display(const list<int> &l1)
{
cout << "L -> ";
for (auto i = l1.begin(); i != l1.end(); ++i)
{
cout << *i << " ";
}
cout << endl;
cout << "R -> ";
for (auto i = l1.rbegin(); i != l1.rend(); ++i)
{
cout << *i << " ";
}
cout << endl;
}
int main()
{
list<int> l1;
int t;
cin >> t;
while (t--)
{
int x, n;
cin >> x >> n;
switch (x)
{
case 0:
l1.push_front(n);
display(l1);
break;
case 1:
l1.push_back(n);
display(l1);
break;
case 2:
if (n < l1.size())
{
l1.erase(next(l1.begin(), n));
}
display(l1);
break;
}
}
return 0;
}