Lecture 11
Learning objectives
After this class, you should be able to:
- Given certain operations on a deque, draw a figure that shows its state at the end of those operations.
- Give the time complexity of the different operations on a deque.
- Implement features of a deque.
- Give applications where a deque can be useful.
Reading assignment
- Section 3.8 (up to fig 3.27), class notes for deque implementation (do not use the one in the book).
- Optional: Fall 2003 lecture notes has additional explanations on deques (chapter 9).
- Page 137 and 138.
Exercises and review questions
- Exercises and review questions on current lecture's material
- Give a sequence of operations such that a deque looks as shown in the figure below. Also give the array positions corresponding to the beginning and end of the deque.
- Let us assume a deque has the following data:
and we now try to insert an 'e'. Show how the deque will look like after this insert operation.
- Implement the
back
member function of a deque.
- Implement the
front
member function of a deque.
- Implement the
push_back
member function of a deque.
- Implement the
pop_back
member function of a deque.
- Implement the
pop_front
member function of a deque.
- Implement the
[]
operator of a deque.
- If a deque looked liked in the previous question, and we
push_front
an e
, but want the new deque to look like:
then how should the push_front
code be changed? Note that this is a different implementation of a deque.
- Questions on next lecture's material
- Assume that we perform the following operation on the rightmost figure in Fig. 4.1 (page 138): push(8); pop(); pop();. Draw the state of the stack on the conclusion of the above operations.
Last modified: 3 Aug 2005