Implement a double-ended queue data structure (often called a dequeue). A dequeue is a data structure supporting the operations push_front(int), push_back(int), pop_front(), pop_back(). A dequeue is supposed to work like a queue except you are allowed to pop elements from both sides and push elements on both sides. For example push_front(1), push_front(2), push_front(3), pop_back() should return 1. pop_front() should return 3. Another way to imagine this data structure is as two stacks sharing their bottom. If you only use push_front and pop_front, the data structure should behave exactly like a stack (similarly if you use only push_back and pop_back).
Note: The space and time efficiency of your implementation will certainly have an impact on your grade.
Recall our implementation of a stack that expands to hold more data. We followed the approach of doubling the available space whenever we run out of storage.
Another observation is that in some cases the stack could hold a large number of elements for only a short time after which most of them are popped and the stack is mostly empty. (Think of 1000 pushes, followed by 950 pops. followed by a sequence of 10000000 alternating pushes and pops. For the largest part of its lifetime the stack needs around 50 positions, but it will always have size at least 1000). This wastes space, so an idea would be to pick a shrinkage factor d. Whenever elements < (1/d)size (i.e. less than 1/d of the array is in use) we will shrink our storage to a smaller size
Note: This is an essay question. Think about it and submit a txt or pdf file with your ideas, no need to program anything (unless it will help you think these questions through). Reading section 3.2 of the Mehlhorn-Sanders book may be enlightening (you don't have to understand the proofs, just the gist of what they are saying).