Stack

8,325 views
8,238 views

Published on

Published in: Technology, Spiritual
1 Comment
7 Likes
Statistics
Notes
No Downloads
Views
Total views
8,325
On SlideShare
0
From Embeds
0
Number of Embeds
960
Actions
Shares
0
Downloads
0
Comments
1
Likes
7
Embeds 0
No embeds

No notes for slide

Stack

  1. 1. S T A C K Based on Chapter 3 Of Reference Book #1
  2. 2. Reference Books <ul><ul><ul><li>Data Structures and Algorithm Analysis in C </li></ul></ul></ul><ul><ul><ul><ul><li>By Mark Allen Weiss </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>Published by Addison Wesley </li></ul></ul></ul></ul></ul><ul><ul><ul><li>Data Structures (Schaum’s Outline Series) </li></ul></ul></ul><ul><ul><ul><ul><li>By Seymour Lipschutz </li></ul></ul></ul></ul><ul><ul><ul><ul><ul><li>Published by Mc Graw Hill </li></ul></ul></ul></ul></ul>
  3. 3. A STACK Model <ul><li>Definitions </li></ul><ul><ul><li>A STACK is a list with the restriction that insertion and deletion can be performed in only one position.for that reason it is called LIFO (last in first out ) structure. </li></ul></ul><ul><ul><li>The end where insertion and deletion can be performed is called the end of the list or top. </li></ul></ul><ul><li>Set of operations </li></ul><ul><ul><li>PUSH , i nserts a new element at the end or top . </li></ul></ul><ul><ul><li>POP , deletes or remove most recently inserted element from top. </li></ul></ul><ul><ul><li>TOP, retrieves most recently inserted element from top. </li></ul></ul><ul><ul><li>isEmpty , returns the status of emptiness of the stack. </li></ul></ul><ul><ul><li>A pop operation on top on an empty stack is considered as an error. </li></ul></ul><ul><ul><li>A push on a full stack cause a overflow condition. </li></ul></ul>
  4. 4. Stack Model
  5. 5. Implementation <ul><ul><li>As Linked List </li></ul></ul><ul><ul><ul><li>PUSH = insertion at front of the list. </li></ul></ul></ul><ul><ul><ul><li>POP = retrieving and deletion at the front of the list </li></ul></ul></ul><ul><ul><ul><li>TOP = retrieving the value of the front node </li></ul></ul></ul>
  6. 6. Linked List implementation Declarations
  7. 7. Linked List implementation Empty Test Create Stack
  8. 8. Linked List implementation PUSH TOP
  9. 9. Linked List implementation POP
  10. 10. Implementation <ul><ul><li>As Array </li></ul></ul><ul><ul><ul><li>Define an Array ‘ Stack ’ of sufficient capacity to store stack elements. </li></ul></ul></ul><ul><ul><ul><li>Uses a variable i.e TopOfStack to remember the position of TOP. </li></ul></ul></ul><ul><ul><ul><li>TopOfStack = -1 for an empty stack. </li></ul></ul></ul><ul><ul><ul><li>PUSH: </li></ul></ul></ul><ul><ul><ul><ul><li>Set TopOfStack = TopOfStack +1 </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Set Stack[TopOfStack] = X </li></ul></ul></ul></ul><ul><ul><ul><li>POP: </li></ul></ul></ul><ul><ul><ul><ul><li>Return Stack[TopOfStack] </li></ul></ul></ul></ul><ul><ul><ul><ul><li>Set TopOfStack = TopOfStack –1 </li></ul></ul></ul></ul>
  11. 11. Array implementation Declarations
  12. 12. Array implementation Create Stack
  13. 13. Array implementation Free the Stack Check for Empty stack
  14. 14. Array implementation Empty the Stack PUSH
  15. 15. Array implementation TOP POP TOP and POP
  16. 16. Applications Postfix Notation
  17. 17. Applications Postfix Notation 6 5 2 3 + 8 * + 3 + *
  18. 18. Applications Postfix Notation 6 5 2 3 + 8 * + 3 + *
  19. 19. Applications Postfix Notation 6 5 2 3 + 8 * + 3 + *
  20. 20. Applications Infix to Postfix a + b * c + ( d * e + f ) * g
  21. 21. Applications Infix to Postfix a + b * c + ( d * e + f ) * g
  22. 22. Applications Infix to Postfix a + b * c + ( d * e + f ) * g
  23. 23. Applications Infix to Postfix a + b * c + ( d * e + f ) * g
  24. 24. Applications Infix to Postfix a + b * c + ( d * e + f ) * g
  25. 25. Applications Infix to Postfix a + b * c + ( d * e + f ) * g
  26. 26. Applications Infix to Postfix a + b * c + ( d * e + f ) * g
  27. 27. Applications Infix to Postfix a + b * c + ( d * e + f ) * g
  28. 28. Applications Infix to Postfix a + b * c + ( d * e + f ) * g Function Calls ( another application )
  29. 29. a + b * c + ( d * e + f ) * g Infix to Postfix a + b * c + ( d * e + f ) * g a + b * c + ( d * e + f ) * g + * + ( * + ) *

×