Professional Documents
Culture Documents
Stack
cafeteria-tray holder
1
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
Stack Representation
Two ways to represent a stack
insertion, deletion, and retrieval are done from the last element in the array
(Arr[n]).
used when the maximum size of the stack is known.
2
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
Stack Operations
3
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
4
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
Function Calls
When PROC1 begins executing, the stack will contain:
5
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
Function Calls
When FUNC1 will reference FUNC2, the stack will contain the following
information:
6
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
Function Calls
The stack will now contain:
7
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
This expression has 5 operands: A,B,C,D and E and uses 3 operators: *, +, and /.
8
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
Evaluation of Expressions
* and / - have equal precedence
+ and - have equal precedence
In evaluating any given expression, operators with a higher precedence are
processed first. When two adjacent operators in an expression have the same
precedence, evaluation is performed from left-to-right.
9
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
Evaluation of Expressions
Any expression within a pair of parentheses will have the highest precedence and
will be evaluated first.
10
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
Evaluation of Expressions
11
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
POSTFIX Notation
12
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
POSTFIX Notation
13
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
POSTFIX Notation
14
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
CLASSWORK
Determine the output of the Postfix algorithm when the following expressions
are used as input.
15
CC103 - Data Structure and Algorithm
LESSON 1: Orientation and Course Introduction
THE END