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