Title: Math Review - Proof By Induction
1ADT 2 The Stack
A stack is a list in which insertions and
removals can only transpire at one end of the
list, i.e., the top of the stack.
2Example Stack Application Arithmetic Expressions
Stacks can be used to convert infix expressions
into postfix expressions
Following these rules, then, the infix expression
7 6 - 3 ( 5 8 / 2 ) is converted into the
postfix expression 7 6 3 5 8 2 / -
3Arithmetic Expression Evaluation (continued)
Then a separate stack can be used to evaluate the
postfix expression
Following these rules with the postfix expression
7 6 3 5 8 2 / - yields
7
13
-14
4Stack Implementation Alternatives
- An Array Implementation
- Positives
- Avoids pointers
- Trivial implementation
- Negatives
- Size must be declared in advance
- A Linked List Implementation
- Positives
- Dynamically allocates exactly the right amount of
memory - Straightforward (if not quite trivial)
implementation - Negatives
- Those wonderful pointers
5ADT 3 The Queue
A queue is a list in which insertions can only
occur at one end of the list (the front of the
queue) and removals can only occur at the
opposite end of the list (the back of the queue).
6Example Queue Application Server Access
The first-come, first-served nature of the
queue ADT can be adapted to providing orderly
access to file servers, print servers, Web
servers, etc.
7Queue Implementation Alternatives
- An Array Implementation
- Positives
- Avoids pointers
- Negatives
- Size must be declared in advance
- Wraparound is needed to avoid false overflows
- A Linked List Implementation
- Positives
- Dynamically allocates exactly the right amount of
memory - Wraparound problem is circumvented
- Negatives
- Our friendly neighborhood pointers