Lecture 12
Learning objectives
After this class, you should be able to:
- Given certain operations on a stack or a deque, draw a figure that shows the state of the data structure at the end of those operations.
- Give the time complexity of the different operations on a stack or a queue.
- Implement features of a stack or a queue, using other data structures, such as deques or linked lists.
- Give applications where stacks or queues can be useful.
- Given a problem, use stacks or queues to solve the problem.
Reading assignment
- Section 4.1-4.2, section 4.3 (the need for a priority queue).
- Sec 4.4.
Exercises and review questions
- Exercises and review questions on current lecture's material
- Chapter 4, exercise 3a.
- Chapter 4, exercise 3b.
- Let us perform the following operations on a stack: push(3), push(2), push(1), pop(). Draw a figure to show the state of the stack. If the underlying data structure were a deque, with initial capacity 2, then show the final state of the deque too. If the underlying data structure were a doubly-linked list, then show the final state of the list too.
- Let us perform the following operations on a queue: push(3), push(2), push(1), pop(). Draw a figure to show the state of the queue. If the underlying data structure were a deque, with initial capacity 2, then show the final state of the deque too. If the underlying data structure were a doubly-linked list, then show the final state of the list too.
- Will it be efficient to implement a stack using a vector?
- Will it be efficient to implement a queue using a vector?
- Will it be efficient to implement a stack using a singly linked list?
- Will it be efficient to implement a queue using a singly linked list?
- Show an implementation of a stack's
pop
andpush
functions, where the underlying data structure is a doubly linked list.- Give a real-world application for (i) stacks and (ii) queues. (Post your answer on the discussion board)
- Questions on next lecture's material
- Write code to insert the following
int
s into an STLstack
object, in the order given below, and then pop them all:1, 2, 3, 4
. In which order are they popped?
Last modified: 14 Feb 2008.