Professional Documents
Culture Documents
DSTR Topic08 Stacks
DSTR Topic08 Stacks
Top of
Top of A
stack
stack
pop (remove)
Top of
stack B Top of
A stack A
5
Topic 08: Stacks AY2022/23S1
6
Topic 08: Stacks AY2022/23S1
Stack Implementation (with a Python List)
Instead of:
A * B + C / D Infix
We represent it as:
A B * C D / + Postfix
12
Topic 08: Stacks AY2022/23S1
Prefix / Infix / Postfix Expressions
13
Topic 08: Stacks AY2022/23S1
Prefix / Infix / Postfix Expressions
*+ab-cd (a + b) * (c - d) ab+cd-*
A=8 C=3
B=2 D=4
A=8 C=3
B=2 D=4
Expression: 20 6 * 8 2 - / 4 * 15 -
2
Stack
6 8 8 6 4 15