CS 112
Lecture 10
Applications of Stacks
Reading: Ch. 8 textbook. Stacks, introduction. Then only
8.3 (implementation of stacks using arrays) and 8.6
(applications of the Stack ADT). No class templates yet. No
implementation of stacks using lists.
Note that I will cover more than just what is in the textbook about
the Polish notation and the Calculator program.
Review
- Stacks.
- The
Stack abstract data type.
- Code from the textbook. Discussion.
Applications of Stacks
- Evaluating arithmetic expressions. A special notation easily
understood by computers: Reverse Polish Notation.
- Fully parenthesized arithmetic expressions.
- Binary expression trees.
-
Polish notation.
Prefix, infix and postfix form.
- Evaluating arithmetic expressions in postfix form using a
stack.
- Work out a few examples.
- A simpler applet, just for
matching parentheses.
- Implementing this algorithm (evaluation of arithmetic
expressions in postfix form) in C++ will be the topic of the next
homework 6 (after the midterm exam).
- We'll get back to this topic later in a few weeks, and you
will implement the algorithm to convert an arithmetic expression
to postfix form (and more).
- We'll see more about trees in a few weeks - and you will
implement this data structure.
- After midterm, we will be discussing the next homework: the arithmetic
expression class. For the midterm, you only need to
understand the theory behind it.
Next time and next week, before the exam
- More on recursive definitions.
- More applications of stacks: memory allocation for function calls.
- Midterm review; what we did so far, what will be on the exam.
Warning:
The topics covered in these two classes are VERY important. Without a clear
understanding of these applications of stacks, you might have
serious difficulty in this class from now on. Please stop me,
ask frequent questions, work out examples on your own after
class, come to my office hours and make sure everything is absolutely
clear before the exam. The next homework will be a
relatively challenging one and requires thorough understanding of
these concepts.
Ileana Streinu