Question: Develop a python class that will offer all the functionalities of traditional deque data structure with the property that the data items can be added

Develop a python class that will offer all the functionalities of traditional deque data structure with the property that the data items can be added and removed both from the front and back. This class should have the following functions implemented.

add_first(e): Add element e to the front of deque. add_last(e): Add element e to the back of deque. delete_first(): Remove and return the first element from deque; an error occurs if the deque is empty. delete_last(): Remove and return the last element; an error occurs if the deque is empty. first(): Return(but do not remove) the first element of deque; an error occurs if the deque is empty. last(): Return (but do not remove) the last deque element; an error occurs if the deque is empty. is_empty(): Return True if deque does not contain any elements. length(): Return the number of elements in the deque. print_deque(): Prints all the items currently present in the deque from the first inserted item to the last one. Note: this function does not remove any item from the internal list.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!