1 / 9

Data Structures - Stacks

Data Structures - Stacks. What are data structures?. Different ways to organize data What data structures have we used before? lists / arrays Deck (AceyDeucey) AddressBook and more!. Introducing the Stack. LIFO ~ Last In First Out How does a stack of trays/plates work?

cshay
Télécharger la présentation

Data Structures - Stacks

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. Data Structures - Stacks

  2. What are data structures? • Different ways to organize data • What data structures have we used before? • lists / arrays • Deck (AceyDeucey) • AddressBook • and more!

  3. Introducing the Stack • LIFO ~ Last In First Out • How does a stack of trays/plates work? • Start with an empty stack • Place tray on top of stack • Place another tray on top of the stack • Remove tray on top from stack • etc. • push– data is added to the top of the stack • pop – data is removed from the top of the stack • isEmpty – returns True if stack is empty

  4. Stack Example PUSH A PUSH C PUSH D PUSH C var1 = POP var2 = POP

  5. Why do we use stacks? • Used to keep track of things in the order that they occur • Continually PUSH things onto the stack • To go back, we POP things off the stack • Example: PUSH A PUSH C PUSH D PUSH C POP POP POP POP

  6. Stack Applications • Whenever we want to remember a “history” so as to go backwards and forwards • Examples on the computer?

  7. Stack Implementation • How do we implement a stack? • Static size vs. Dynamic size

  8. Dynamic size • Draw a stack using a list • What does an empty stack look like? • Push a number (8) • Push a number (6) • What should be the top? • How should we remember/track the top? • Pop! What happens?

  9. Static size • Draw a stack using an array (already has a size and is filled with zeros • What does an empty stack look like? • Push a number (8) • Push a number (6) • What should be the top? • How should we remember/track the top? • Pop! What happens?

More Related