1 / 83

Stack ADT

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

cera
Download Presentation

Stack ADT

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  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) 212 rules! Ø Ø Ø 30−0 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 Ø 212 rules! Golf #1 30−0

  4. 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 Ø Ø Ø

  5. 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

  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 + *zc ( ^ * + = @

  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

More Related