Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Deque (double-ended queue) is an abstract data structure with the following operation push_frontpush_front adds a key to the head of the deque push_backpush_back adds a

Deque (double-ended queue) is an abstract data structure with the following operation

push_frontpush_front adds a key to the head of the deque

push_backpush_back adds a key to the tail of the deque

pop_frontpop_front extracts a key from the head of the deque and returns it

pop_backpop_back extracts a key from the tail of the deque and returns it

frontfront returns head element without removing it

backback returns tail element without removing it

sizesize returns number of the elements in the deque

clearclear removes all elements from the deque

exitexit print 'bye' in console

Implement DequeDeque class with this methods and error handling. For pop_frontpop_front, pop_backpop_back, frontfront, backback the method has to check are there elements in the deque. If it is empty the method has to return string "error" instead of a numeric value.

push_frontpush_front, push_backpush_back, clearclear methods has to return string ok".

Implement process_deque(commands) which takes commands list and returns a list of answers to each command.

Input data:

Commands in separate lines consisting of strings "push_front x", "push_back x", "pop_front", "pop_back", "front", "back", "size", "clear". Input ends with "exit" command.

len(commands)60000len(commands)60000

Output data:

A list of answers for each command

Example:

Input:Input:

push_front 1

push_front 2

push_back 6

front

back

clear

size

back

Output:Output:

ok

ok

ok

2

6

ok

0

error

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

design a simple performance appraisal system

Answered: 1 week ago