Skip to content

Commit ef2641f

Browse files
committed
Solution code for baekjoon/10866
1 parent 544ad28 commit ef2641f

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

queue/baekjooon/10866/solution.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include <iostream>
2+
#include <deque>
3+
4+
using namespace std;
5+
6+
int main(void)
7+
{
8+
int n = 0;
9+
cin >> n;
10+
11+
deque<int> d;
12+
while (n--)
13+
{
14+
string command;
15+
cin >> command;
16+
17+
int value;
18+
19+
if (command == "push_front")
20+
{
21+
cin >> value;
22+
d.push_front(value);
23+
}
24+
else if (command == "push_back")
25+
{
26+
cin >> value;
27+
d.push_back(value);
28+
}
29+
else if (command == "pop_front")
30+
{
31+
if (d.empty())
32+
{
33+
cout << "-1\n";
34+
}
35+
else
36+
{
37+
cout << d.front() << "\n";
38+
d.pop_front();
39+
}
40+
}
41+
else if (command == "pop_back")
42+
{
43+
if (d.empty())
44+
{
45+
cout << "-1\n";
46+
}
47+
else
48+
{
49+
cout << d.back() << "\n";
50+
d.pop_back();
51+
}
52+
}
53+
else if (command == "size")
54+
{
55+
cout << d.size() << "\n";
56+
}
57+
else if (command == "empty")
58+
{
59+
if (d.empty())
60+
cout << "1\n";
61+
else
62+
cout << "0\n";
63+
}
64+
else if (command == "front")
65+
{
66+
if (d.empty())
67+
cout << "-1\n";
68+
else
69+
cout << d.front() << "\n";
70+
}
71+
else if (command == "back")
72+
{
73+
if (d.empty())
74+
cout << "-1\n";
75+
else
76+
cout << d.back() << "\n";
77+
}
78+
else
79+
{
80+
cout << "Undefined Behavior!";
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)