CC103 - Data Structure and Algorithm
CC103 - Data Structure and Algorithm
CC103 - Data Structure and Algorithm
Week 5:
Stacks
OBJECTIVES:
At the end of the topic session the students are
expected to:
Stack
cafeteria-tray holder
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.
Stack Operations
8
CC103 - Data Structure and Algorithm
LESSON 5: Stacks
Function Calls
When PROC1 begins executing, the stack will contain:
Function Calls
When FUNC1 will reference FUNC2, the stack will contain the following
information:
Function Calls
The stack will now contain:
This expression has 5 operands: A,B,C,D and E and uses 3 operators: *, +, and /.
Evaluation of Expressions
* and / - have equal precedence
- have a higher precedence than + and -
+ and - - have equal precedence
Evaluation of Expressions
Any expression within a pair of parentheses will have the highest precedence and
will be evaluated first.
Evaluation of Expressions
POSTFIX Notation
POSTFIX Notation
POSTFIX Notation
PSEUDOCODE
Representation
PSEUDOCODE
Representation
PSEUDOCODE
Representation
PSEUDOCODE
Representation
PSEUDOCODE
Representation
PSEUDOCODE
Representation
PSEUDOCODE
Representation
CLASSWORK
Determine the output of the Postfix algorithm when the following expressions
are used as input.
THE END