eolymp
bolt
Try our new interface for solving problems
Məsələlər

Deque of infinite size

Deque of infinite size

Implement the "\textit{deque}" data structure. Write a program that describes the deque and simulates its operations. You must implement all methods given below. The program reads the sequence of commands and executes the corresponding operation. After executing each command the program must print one line. The possible commands for the program are: \textbf{push_front} Add (put) into the front of the deque the new element. The program must print \textbf{ok}. \textbf{push_back} Add (put) into the end of the deque the new element. The program must print \textbf{ok}. \textbf{pop_front} Pop the first element from the deque. The program must print its value. \textbf{pop_back} Pop the last element from the deque. The program must print its value. \textbf{front} Find the value of the first element (not deleting it). The program must print its value. \textbf{back} Find the value of the last element (not deleting it). The program must print its value \textbf{size} Print the number of elements in the deque. \textbf{clear} Clear the deque (delete all its elements) and print \textbf{ok}. \textbf{exit} The program must print \textbf{bye} and terminate. The size of the deque is limited only by the available memory. Before the execution of the operations \textbf{pop_front},\textbf{pop_back}, \textbf{front}, \textbf{back} the program should check first whether the deque contains at least one element. When we have the input operation \textbf{pop_front}, \textbf{pop_back}, \textbf{front}, \textbf{back} but the deque is empty, the program must print the line \textbf{error} instead of numeric value. \InputFile Given in the problem statement. Look at sample input. \OutputFile Given in the problem statement. Look at sample output.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 256 MiB
Giriş verilənləri #1
push_back 1
back
exit
Çıxış verilənləri #1
ok
1
bye