Professional Documents
Culture Documents
10 - Lec06 - Stacks-2 PDF
10 - Lec06 - Stacks-2 PDF
10 - Lec06 - Stacks-2 PDF
Stacks
Sidra Malik
sidra.malik@ciitlahore.edu.pk
Stacks
• A stack is a list in which insertion and deletion take place at
the same end
– This end is called top
– The other end is called bottom
Linked-list-based
Empty
maxlength
Top
x y z NULL
A-B/(C*D^E) ABCDE^*/-
ABCDE^*/- -A/B*C^DE
• ( 5 + 6) * 9 +10
• (300+23)*(43-21)/(84+7)
• (4+8)*(6-5)/((3-2)*(2+2))
Example:
2 3 4 + 5 6 - - *
→ 2 3 4 + 5 6 - - *
→ 2 7 5 6 - - *
→ 2 7 5 6 - - *
→ 2 7 -1 - *
→ 2 7 -1 - * → 2 8 * → 2 8 * → 16
Data Structures and Algorithms-Sidra Malik 39
Example: Postfix Expressions