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).
- 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.
a b - Let us assume a deque has the following data:
c d a b and we now try to push_front 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 question 2, and we
push_front
ane
, but want the new deque to look like:
e a b c d then how should the
push_front
code be changed? Note that this is a different implementation of a deque.- Give a real-world application for deques. (Post your answer on the discussion board)
- 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: 12 Feb 2008