1 / 10

CSE 2341 Object Oriented Programming with C++ Note Set #19

CSE 2341 Object Oriented Programming with C++ Note Set #19. Overview. Stack Data Structure. The Stack. STACK data structure that stores and retrieves items in a last-in-first-out manner only have access to element “on top” of the stack How is this different from a basic array?. Stack.

palti
Download Presentation

CSE 2341 Object Oriented Programming with C++ Note Set #19

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. CSE 2341Object Oriented Programming with C++Note Set #19

  2. Overview • Stack Data Structure

  3. The Stack • STACK • data structure that stores and retrieves items in a last-in-first-out manner • only have access to element “on top” of the stack • How is this different from a basic array?

  4. Stack • Think of a stack of plates in a cafeteria last in first out 5 4 3 2 1 last out first in

  5. Applications of Stacks • Used during program execution • Can use a stack to perform mathematical operations • general: useful data structure for any algorithms that work with the last saved element of a series.

  6. 2 Types • Static Stacks • Fixed size • Implemented as Arrays • Dynamic Stacks • ability to grow and shrink as needed. • Implemented as Linked lists

  7. Basic Stack Operations • push(x) • causes a value to be stored or pushed onto the stack Empty Stack push(5) push(10) push(7) 5 10 7 5 10 5

  8. Basic Stack Operations • pop(x) • retrieves (and hence, removes) a value from the stack. 10 5 7 10 5 pop(x) 5 pop(x) pop(x)

  9. Basic Stack Operations • isFull() • boolean function needed with fixed-size stacks • prevents stack overflow from trying to push a value on when there is no more room • isEmpty() • boolean function needed for both fixed and dynamic stacks • prevents any errors from the pop operation on an empty stack.

  10. Fini ?

More Related