Welcome to the Deque Tester! >h q : to quit h : for help ps : to print size of deque pr : to print item at rear of deque pf : to print item at front of deque pd : to print all items in deque rr : to remove item from rear rf : to remove item from front ir x : to insert string x at rear if x : to insert string x at front >ir the Inserting "the" at rear... >if in Inserting "in" at front... >ps Size of deque is 2 >pd Contents of deque: [ in the ] >if cat Inserting "cat" at front... >pd Contents of deque: [ cat in the ] >ps Size of deque is 3 >ir hat Inserting "hat" at rear... >pf Front item is cat >pr Rear item is hat >if A Inserting "A" at front... >pd Contents of deque: [ A cat in the hat ] >rf Removing item at front... >pd Contents of deque: [ cat in the hat ] >ir croaked Inserting "croaked" at rear... >pd Contents of deque: [ cat in the hat croaked ] >rr Removing item at rear... >pd Contents of deque: [ cat in the hat ] >rf Removing item at front... >rf Removing item at front... >rr Removing item at rear... >pd Contents of deque: [ the ] >rf Removing item at front... >pd Contents of deque: [ ] >q Goodbye. |
A deque is a linear container structure, like a stack or a queue. In a stack, insertions and removals of elements occur at the same end (referred to as the top). In a queue, insertions occur at one end (the rear) and removals at the other (the front). A deque combines these capabilities by allowing both insertions and removals to occur at either end. (By convention, we refer to the two ends of a deque using the same terms as in a queue: front and rear.)
Array-based implementations of stacks and queues were covered in lecture. In particular, the array-based implementation of a queue imagined the array as being a "wraparound" or circular structure in which location zero "follows" location N-1 (i.e., the array's last location). (See the relevant links about queues on the CMPS 144 course web page.)
For this activity, you are to complete an array-based implementation of deques that imagines the array as a wraparound structure. You will need these files: