-
Notifications
You must be signed in to change notification settings - Fork 0
/
덱.py
43 lines (39 loc) · 973 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
41
42
43
import sys
from collections import deque
n = int(sys.stdin.readline())
dq = deque()
for i in range(n):
new = sys.stdin.readline().split()
if new[0] == 'push_front':
dq.appendleft(new[1])
elif new[0] == 'push_back':
dq.append(new[1])
elif new[0] == 'pop_front':
if len(dq) == 0:
print(-1)
else :
print(dq[0])
dq.popleft()
elif new[0] == 'pop_back':
if len(dq) == 0:
print(-1)
else:
print(dq[len(dq)-1])
dq.pop()
elif new[0] == 'size':
print(len(dq))
elif new[0] == 'empty':
if len(dq) == 0:
print(1)
else:
print(0)
elif new[0] == 'front':
if len(dq) == 0:
print(-1)
else:
print(dq[0])
else:
if len(dq) == 0:
print(-1)
else:
print(dq[len(dq)-1])