Data Structures Stacks - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Data Structures Stacks

Description:

What data structures have we used before? lists / arrays. deck (Blackjack) and more! Introducing the Stack. LIFO ~ Last In First Out ... – PowerPoint PPT presentation

Number of Views:486
Avg rating:3.0/5.0
Slides: 7
Provided by: paul181
Category:

less

Transcript and Presenter's Notes

Title: Data Structures Stacks


1
Data Structures - Stacks
2
What are data structures?
  • Different ways to organize data
  • What data structures have we used before?
  • lists / arrays
  • deck (Blackjack)
  • 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 pushed on TOP of the stack
  • POP data is popped from TOP of the stack

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 Implementation
  • How do we implement a stack?
  • class
  • array or ArrayList
  • Now lets see some code
Write a Comment
User Comments (0)
About PowerShow.com