Deque with error protection#6129

Deque with error protection

2 seconds
128 megabytes
Very easy

Implement the "deque" data structure. Write a program that contains the description of the deque and implements all the methods mentioned below. The program reads a sequence of commands and, depending on the command, performs the corresponding operation. After each command, the program should print one line. Possible commands for the program are:

push_front

Add an element to the front of the deque. The program must print ok.

push_back

Add an 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

Output the value of the first element (without removing it). The program must print its value.

back

Output the value of the last element (without removing it). The program must print its value.

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.

It is guaranteed that the number of elements in the deque at any time does not exceed . Before executing the operations pop_front, pop_back, front, back the program must check whether there is at least one element in the deque. If one of these operations is called when the deque is empty, the program should print error instead of a value.

// Java OOP
class MyDeque // from problem 6128 Simple deque
{
  protected LinkedList<Integer> v;
  ...
}

class ErrorProtectedDeque extends MyDeque
{
  final static int ERROR = -2000000000;
  public int pop_front();  // in the cases of error, return ERROR
  public int pop_back();  // in the cases of error, return ERROR
  public int front(); // in the cases of error, return ERROR
  public int back();  // in the cases of error, return ERROR
}

Input

Each line contains one command.

Output

For each command, output the result in a separate line.

Examples

Example 1

Loading
Loading

Example 2

Loading
Loading