stacks - Stacks A stack is a data structure in which access...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Stacks A stack is a data structure in which access is only allowed from one end. Imagine the candy Pez dispensers You insert and remove candy from the same end. The first piece in is the last piece out. You have a stack of books - to get to the bottom, you have to remove the ones on top. This is called LIFO - Last-in/First-out
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
java.util.Stack Provides the stack class Constructor isEmpty or empty peek - get the top item without removing it pop - remove the top item push - push a new item onto the stack size - the number of items in a stack
Background image of page 2
Our Stack Push T T T I Push I T I N Push N Pop N T I Pop I T Pop T
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Evaluating Arithmetic Expressions with a Stack Lets assume that the parentheses match up ( (1 + 2)/3) * (6 - 4) ) ( (3 / 3) * (6-4) ) ( 1 * (6 - 4) ) ( 1 * (2 ) ) 1 * 2 = 2
Background image of page 4
Evaluating Arithmetic Expressions using a Stack ( ( (1 + 2) / 3) * (6 - 4) ) Let’s use 2 stacks One storing numbers the other the operations 1 + 2 Read 1, + , 2 Then we hit a Right parenthesis so evaluate stack 3
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/09/2010 for the course CSE 71682 taught by Professor Nakamura during the Spring '10 term at ASU.

Page1 / 10

stacks - Stacks A stack is a data structure in which access...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online