Implement the deque data structure. Write a program that implements and simulates the operations of a deque. You must provide all the methods described below. The program reads a sequence of commands and performs the corresponding operations. After executing each command, the program must print one line. The possible commands are:
push_front
Add a new element to the front of the deque. The program must print ok.
push_back
Add a new element to the back of the deque. The program must print ok.
pop_front
Remove the first element from the deque. The program must print its value.
pop_back
Remove the last element from the deque. The program must print its value.
front
Print the value of the first element (without removing it).
back
Print the value of the last element (without removing it).
size
Print the number of elements in the deque.
clear
Remove all elements from the deque and print ok.
exit
The program must print bye and terminate.
The size of the deque is limited only by the available memory. Before performing the operations pop_front, pop_back, front, or back, the program should first check whether the deque contains at least one element. If one of these operations is performed when the deque is empty, the program must print error instead of a numeric value.
Described in the problem statement. See the sample input.
Described in the problem statement. See the sample output.
Example 1