Notes 10 - Week 10 Stacks Some of the chapters in the text come in pairs one is conceptual the other implementation These chapters will be combined

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

View Full Document Right Arrow Icon
Week 10: Stacks Some of the chapters in the text come in pairs: one is conceptual, the other implementation. These chapters will be combined and treated together with the focus on the conceptual. Def: A stack is a list that can grow and shrink at the head only “last-in, first-out” (same as “first- in, last-out”) Restrict add and remove to insertHead push removeHead pop The top of the stack is the head or firstNode, which is the only location that is accessible The insertion order is chronological, removal in is reverse chronological order. Task 1: Review the ADT on page 535 and interface on page 536 Example: StackInterface aStack = new linkedStack; aStack.pop() // could return null or call an exception aStack.push("Mercury"); aStack.push("Venus"); aStack.puch("Mars"); String top = (String) aStack.peek(); aStack.pop(); String now = (String) aStack.pop(); print top + now Output : MarsVenus and the stack still contains Mercury Task 2: Do #1, 2 on page 453 and check your answers in the appendix. Some uses of Stacks 1. Checking balanced parentheses in Infix expressions 2. Convert infix to postfix 3. Postfix execution 4. Infix execution (i.e. convert to postFix then execute postFix) 5. Return from procedure calls / recursive calls Algebraic Forms
Background image of page 1

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

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

This note was uploaded on 01/23/2012 for the course CS 111C taught by Professor Metzler during the Spring '11 term at City College of San Francisco.

Page1 / 4

Notes 10 - Week 10 Stacks Some of the chapters in the text come in pairs one is conceptual the other implementation These chapters will be combined

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

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