Question: 18 points) Question 3: Develop a python class that will offer all the functionalities of traditional deque data structure with the property that the data

18 points) Question 3: 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 from deque; 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. Note: You cannot use the insert, append, or pop function in the python list. Only, way you can update the content of the list is through an assignment operation on a certain index position. For example: self. data[i] = value or self.data [1+1]= self.data[ii). Use the following constructor for the Deque class, where n is the maximum size of the deque object. The maximum size of the deque would be already known. Class Deque: init_(self, n) : def self.data =[None]n self.max_size =n self.length =0 self.first =n1// it can be something else too based on your implementation self.last =0 //it can be something else too based on your implementation (4 points) Question 4: Write codes to create an instance of the Deque class (D= Deque(10)) and perform the following operations in this sequence with the Deque object D: 1. D.delete_last() 2. D.add last (50) 3. D.add_first(2) 4. D.delete last() 5. D.print_deque() 6. D.add first(10) 7. D.add first (100) 8. D.add_last(1) 9. D.delete last() 10. D.delete first() 11. D.length() 12. D.print deque()
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
