Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- d = []
- head = 0
- size = 0
- tail = 0
- data = 0
- def push_front(data):
- d.insert(head, data)
- size += 1
- def push_back(data):
- d.append(data)
- size += 1
- tail += 1
- def pop_front():
- p = d[head]
- head += 1
- size -= 1
- return p
- def pop_back():
- p = p[tail]
- tail -= 1
- size -= 1
- return p
- def front():
- return d[head]
- def back():
- return d[tail]
- f = open('input.txt')
- for line in f:
- s = line.split()
- if (s[0] == 'push_front'):
- push_front(s[1])
- print('ok')
- if (s[0] == 'push_back'):
- push_back(s[1])
- print('ok')
- if (s[0] == 'pop_front'):
- if (size > 0):
- data = pop_front()
- print(data)
- else:
- print('error')
- if (s[0] == 'pop_back'):
- if (size > 0):
- data = pop_back()
- print(data)
- else:
- print('error')
- if (s[0] == 'front'):
- if (size > 0):
- data = front()
- print(data)
- else:
- print('error')
- if (s[0] == 'back'):
- if (size > 0):
- data = back()
- print(data)
- if (s[0] == 'size'):
- print(size)
- if (s[0] == 'clear'):
- head = 0
- tail = 0
- size = 0
- print('ok')
- if (s[0] == 'exit'):
- print('bye')
- exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement