Deque
InterviewTime limit0.5sMemory limit256 MB
Process up to 10000 push, pop, size, empty, front and back commands on an integer deque and print each query result.
- Level
Easy3 of 10
- Topics
- Queue, Implementation
- Solved
- No attempts yet
Problem
Implement a deque that stores integers, then write a program that processes the commands given on the input.
There are eight commands.
push_front X: put the integer X at the front of the deque.push_back X: put the integer X at the back of the deque.pop_front: remove the number at the front of the deque and print it. If the deque is empty, print -1.pop_back: remove the number at the back of the deque and print it. If the deque is empty, print -1.size: print how many integers the deque holds.empty: print 1 if the deque is empty, and 0 if it is not.front: print the integer at the front of the deque. If the deque is empty, print -1.back: print the integer at the back of the deque. If the deque is empty, print -1.
Input
The first line holds the number of commands (). Each of the next lines holds one command. Every integer given is at least 1 and at most 100000. No command other than the eight listed above is given.
Output
Each time a command that has to print something is given, print its result on its own line.