Java Reference
In-Depth Information
Chapter
5
Stacks
Contents
Specifications of the ADT Stack
Using a Stack to Process Algebraic Expressions
A Problem Solved: Checking for Balanced Delimiters in an Infix Algebraic Expression
A Problem Solved: Transforming an Infix Expression to a Postfix Expression
A Problem Solved: Evaluating Postfix Expressions
A Problem Solved: Evaluating Infix Expressions
The Program Stack
Java Class Library: The Class Stack
Prerequisites
Appendix D Designing Classes
Chapter 1
Bags
Objectives
After studying this chapter, you should be able to
Describe the operations of the ADT stack
Use a stack to decide whether the delimiters in an algebraic expression are paired correctly
Use a stack to convert an infix expression to a postfix expression
Use a stack to evaluate a postfix expression
Use a stack to evaluate an infix expression
Use a stack in a program
Describe how the Java run-time environment uses a stack to track the execution of methods
I n everyday life, a stack is a familiar thing. You might see a stack of topics on your
desk, a stack of dishes in the cafeteria, a stack of towels in the linen closet, or a stack
of boxes in the attic. When you add an item to a stack, you place it on top of the stack.
When you remove an item, you take the topmost one. This topmost item is the last
one that was added to the stack. So when you remove an item, you remove the item
added most recently. That is, the last item added to the stack is the first one removed.
 
 
 
Search WWH ::




Custom Search