850 likes | 1.1k Views
Stack ADT. Operations Push, Pop, Top, isEmpty Application: Expression Evaluation Arithmetic Expression Infix-to-Postfix Postfix to Quadruples Boolean Expressions (Assignment #1) Infix-to-Postfix Postfix to Quadruples. Implementing a Stack. Using Vector /Array
E N D
Stack ADT • Operations • Push, Pop, Top, isEmpty • Application: Expression Evaluation • Arithmetic Expression • Infix-to-Postfix • Postfix to Quadruples • Boolean Expressions (Assignment #1) • Infix-to-Postfix • Postfix to Quadruples
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) 212 rules! Ø Ø Ø 30−0 Golf #1 top
Implementing a Stack • Using Linked List • flexible, adjusts to problem size • implementing a linked list • nodes and references/links/pointers top Ø 212 rules! Golf #1 30−0
Implementing a Stack 0 1 2 3 4 5 6 7 8 2 -1 7 -1 1 4 3 6 0 Ø • Using Linked List • implementing a linked list • cursor implementation 212 rules! Ø Ø 30−0 top = 5 Golf #1 freelist = 8 Ø Ø Ø
Implementing a Stack 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
Infix to Postfix infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: @
Infix to Postfix infix expression: z= a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z @
Infix to Postfix infix expression: z= a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z = @
Infix to Postfix infix expression: z=a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a = @
Infix to Postfix infix expression: z=a* ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a * = @
Infix to Postfix infix expression: z=a*( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a ( * = @
Infix to Postfix infix expression: z=a*(x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x ( * = @
Infix to Postfix infix expression: z=a*(x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x + ( * = @
Infix to Postfix infix expression: z=a*(x +y ) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + ( * = @
Infix to Postfix infix expression: z=a*(x +y) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + ( * = @
Infix to Postfix infix expression: z=a*(x +y) + z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * = @
Infix to Postfix infix expression: z=a*(x +y)+ z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * = @
Infix to Postfix infix expression: z=a*(x +y)+ z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + * + = @
Infix to Postfix infix expression: z=a*(x +y)+z * c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + *z + = @
Infix to Postfix infix expression: z=a*(x +y)+z* c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + *z * + = @
Infix to Postfix infix expression: z=a*(x +y)+z*c ^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + *z c * + = @
Infix to Postfix infix expression: z=a*(x +y)+z*c^ ( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + *z c ^ * + = @
Infix to Postfix infix expression: z=a*(x +y)+z*c^( 2 − ( − d + w ) ) / x ; postfix expression: z a x y + *zc ( ^ * + = @
Infix to Postfix infix expression: z=a*(x +y)+z*c^( 2− ( − d + w ) ) / x ; postfix expression: z a x y + *z c 2 ( ^ * + = @
Infix to Postfix infix expression: z=a*(x +y)+z*c^( 2− ( − d + w ) ) / x ; postfix expression: z a x y + *z c 2 − ( ^ * + = @
Infix to Postfix infix expression: z=a*(x +y)+z*c^( 2−(− d + w ) ) / x ; postfix expression: z a x y + *z c 2 ( − ( ^ * + = @
Infix to Postfix infix expression: z=a*(x +y)+z*c^( 2−(− d + w ) ) / x ; postfix expression: z a x y + *z c 2 ~ ( − ( ^ * + = @
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 ~ ( − ( ^ * + = @
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 ~ ( − ( ^ * + = @
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 ~ ( − ( ^ * + = @
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 ~ + ( − ( ^ * + = @
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 + ( − ( ^ * + = @
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 + ( − ( ^ * + = @
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 + ( − ( ^ * + = @
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 + ( − ( ^ * + = @
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 + − ( ^ * + = @
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 + − ( ^ * + = @
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 + − ( ^ * + = @
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 + − ^ * + = @
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 + − ^ * + = @
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 + − ^ * + = @
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 + − ^ * + = @
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 + − ^ * / + = @
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 / + = @
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 / + = @
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 / + = @
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 / + = @
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 / + = @
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 / + =
Postfix to Quadruples postfix expression: z a x y + * z c 2 d ~w + − ^ * x / + = z