-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0707_deque.py
More file actions
41 lines (38 loc) · 865 Bytes
/
Copy path0707_deque.py
File metadata and controls
41 lines (38 loc) · 865 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
import sys
N= int(sys.stdin.readline())
result =[]
for i in range(N):
n = len(result)
cmd = sys.stdin.readline()[:-1]
temp=[]
if cmd[0:10] == "push_front":
result = [int(cmd[11:])]+result
elif cmd[0:9] == "push_back":
result.append(int(cmd[10:]))
elif cmd =="pop_front":
if n ==0:
print(-1)
else:
print(result.pop(0))
elif cmd =="pop_back":
if n == 0:
print(-1)
else:
print(result.pop())
elif cmd=="size":
print(n)
elif cmd=="empty":
if n ==0:
print(1)
else:
print(0)
elif cmd =="front":
if n ==0:
print(-1)
else:
print(result[0])
elif cmd =="back":
if n ==0:
print(-1)
else:
print(result[-1])