Download presentation
Presentation is loading. Please wait.
Published byDeddy Ivan Oesman Modified over 6 years ago
1
Stack ADT Operations Application: Expression Evaluation
Push, Pop, Top, isEmpty Application: Expression Evaluation Arithmetic Expression Infix-to-Postfix Postfix to Quadruples Boolean Expressions (Assignment #1)
2
Implementing a Stack Using Vector /Array
requires estimate of maximum list length may grow dynamically Ø = empty slots Can contain varied data/objects (not necessarily homogeneous) 30−0 212 rules! Golf #1 Ø Ø Ø top
3
Implementing a Stack Using Linked List
flexible, adjusts to problem size implementing a linked list nodes and references/links/pointers top Golf #1 212 rules! 30−0 Ø
4
Implementing a Stack Using Linked List implementing a linked list 1 2
1 2 3 4 5 6 7 8 Ø 2 -1 7 1 4 3 6 Using Linked List implementing a linked list cursor implementation 212 rules! Ø Ø 30−0 top = 5 Golf #1 freelist = 8 Ø Ø Ø
5
Implementing a Stack push O(1)* O(1) pop O(1) O(1) top/peek O(1) O(1)
Vector/Array Linked List push O(1)* O(1) pop O(1) O(1) top/peek O(1) O(1) isEmpty O(1) O(1) *assuming no need for Vector/Array expansion
6
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: @
7
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z @
8
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z = @
9
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a = @
10
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a * = @
11
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a ( * = @
12
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x ( * = @
13
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x + ( * = @
14
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + ( * = @
15
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + ( * = @
16
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * = @
17
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * = @
18
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * + = @
19
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z + = @
20
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z * + = @
21
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c * + = @
22
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c ^ * + = @
23
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c ( ^ * + = @
24
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 ( ^ * + = @
25
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 − ( ^ * + = @
26
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 ( − ^ * + = @
27
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 ~ ( − ^ * + = @
28
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ ( − ^ * + = @
29
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ ( − ^ * + = @
30
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ ( − ^ * + = @
31
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ + ( − ^ * = @
32
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + ( − ^ * = @
33
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + ( − ^ * = @
34
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + ( − ^ * + = @
35
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + ( − ^ * + = @
36
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ( ^ * + = @
37
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ( ^ * + = @
38
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ( ^ * + = @
39
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ^ * + = @
40
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ^ * + = @
41
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ^ * + = @
42
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ^ * + = @
43
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ^ * / + = @
44
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = @
45
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = @
46
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = @
47
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = @
48
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = @
49
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + =
50
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = z
51
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = a z
52
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = x a z
53
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = y x a z
54
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = y x a z
55
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = t0 a z + x y t0
56
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 t0 a z
57
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 t1 z
58
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 z t1
59
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 c z t1
60
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 2 c z t1
61
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 d 2 c z t1
62
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 d 2 c z t1
63
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 t2 2 c z t1
64
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 w t2 2 c z t1
65
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 w t2 2 c z t1
66
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 t3 2 c z t1
67
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 t3 2 c z t1
68
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 t4 c z t1
69
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 t4 c z t1
70
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 ^ c t4 t5 t5 z t1
71
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 ^ c t4 t5 t5 z t1
72
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 ^ c t4 t5 * Z t5 t6 t6 t1 z
73
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 ^ c t4 t5 * Z t5 t6 x t6 t1 z
74
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 ^ c t4 t5 * Z t5 t6 x t6 t1 z
75
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 ^ c t4 t5 * Z t5 t6 / t6 x t7 t7 t1 z
76
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 ^ c t4 t5 * Z t5 t6 / t6 x t7 t7 t1 z
77
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 ^ c t4 t5 * Z t5 t6 / t6 x t7 + t1 t7 t8 t8 z
78
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 ^ c t4 t5 * Z t5 t6 / t6 x t7 + t1 t7 t8 t8 z
79
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 ^ c t4 t5 * Z t5 t6 / t6 x t7 + t1 t7 t8 = t8 z
80
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 ^ c t4 t5 * Z t5 t6 / t6 x t7 + t1 t7 t8 t8 z
81
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 ^ c t4 t5 * Z t5 t6 / t6 x t7 + t1 t7 t8 = t8 z
82
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + = + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - 2 t3 t4 ^ c t4 t5 * Z t5 t6 / t6 x t7 + t1 t7 t8 = t8 z
83
Postfix to Quadruples infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; --- t t2- ----- t t3 ---- t t t t t + x y t0 * a t0 t1 ~ d t2 + t2 w t3 - w t3 t4 ^ c t4 t5 * Z t5 t6 / t6 x t7 + t1 t7 t8 = t8 z postfix expression: z a x y + * z c 2 d ~ w + − ^ * x / + =
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.