-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path덱.py
40 lines (38 loc) · 867 Bytes
/
덱.py
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
from collections import deque
import sys
input = sys.stdin.readline
n = int(input())
dq = deque([])
for i in range(n):
com = input().rstrip().split()
if com[0] == "push_back":
dq.append(int(com[1]))
elif com[0] == "push_front":
dq.appendleft(int(com[1]))
elif com[0] == "pop_back":
if dq:
print(dq.pop())
else:
print(-1)
elif com[0] == "pop_front":
if dq:
print(dq.popleft())
else:
print(-1)
elif com[0] == "size":
print(len(dq))
elif com[0] == "empty":
if dq:
print(0)
else:
print(1)
elif com[0] == "front":
if dq:
print(dq[0])
else:
print(-1)
elif com[0] == "back":
if dq:
print(dq[-1])
else:
print(-1)