Lecture 10 - The Stack and Queue Types

Lecture 10 - The Stack and Queue Types - The Stack and...

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

View Full Document Right Arrow Icon
The Stack and Queue Types Lecture 10 Hartmut Kaiser hkaiser@cct.lsu.edu http://www.cct.lsu.edu/˜hkaiser/fall_2011/csc1254.html
Background image of page 1

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

View Full DocumentRight Arrow Icon
Programming Principle of the Day Do the simplest thing that could possibly work ▫ A good question to ask one’s self when programming is “What is the simplest thing that could possibly work?” ▫ This helps keep us on the path towards simplicity in the design. http://c2.com/xp/DoTheSimplestThingThatCouldPossiblyWork.html 9/22/2011, Lecture 10 CSC 1254, Fall 2011, Stacks and Queues 2
Background image of page 2
Abstract This lecture will focus on two other sequential data types, the stack and the queue. We will use stacks to implement conversion between ‘normal expressions’ and the equivalent reverse polish notation. 9/22/2011, Lecture 10 CSC 1254, Fall 2011, Stacks and Queues 3
Background image of page 3

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

View Full DocumentRight Arrow Icon
Introduction to Stacks A stack is a last-in-first-out (LIFO) data structure Limited access vector (or list) Main operations: ▫ Adding an item Referred to as pushing it onto the stack ▫ Removing an item Referred to as popping it from the stack CSC 1254, Fall 2011, Stacks and Queues 4 9/22/2011, Lecture 10
Background image of page 4
CSC 1254, Fall 2011, Stacks and Queues 5 Introduction to Stacks Definition: ▫ An ordered collection of data items ▫ Can be accessed at only one end (the top) Operations: ▫ Construct a stack (usually empty) ▫ Check if it is empty ▫ push: add an element to the top ▫ top: retrieve the top element ▫ pop: remove the top element ▫ size: returns number of elements in stack 9/22/2011, Lecture 10
Background image of page 5

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

View Full DocumentRight Arrow Icon
Introduction to Stacks Useful for ▫ Reversing a sequence ▫ Managing a series of undo-actions ▫ Tracking history when browsing the web ▫ Function call hierarchy is implemented with a stack 9/22/2011, Lecture 10 CSC 1254, Fall 2011, Stacks and Queues 6
Background image of page 6
7 Push 17 5 11 3 Push means place a new data element at the top of the stack 9/22/2011, Lecture 10 CSC 1254, Fall 2011, Stacks and Queues
Background image of page 7

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

View Full DocumentRight Arrow Icon
8 Push (cont.) 17 5 11 3 Push means place a new data element at the top of the stack 9/22/2011, Lecture 10 CSC 1254, Fall 2011, Stacks and Queues
Background image of page 8
9 Push (cont.) 17 5 11 3 Push means place a new data element at the top of the stack 9/22/2011, Lecture 10 CSC 1254, Fall 2011, Stacks and Queues
Background image of page 9

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

View Full DocumentRight Arrow Icon
10 Push (cont.) 17 5 11 3 Push means place a new data element at the top of the stack 9/22/2011, Lecture 10 CSC 1254, Fall 2011, Stacks and Queues
Background image of page 10
11 Pop 17 5 11 3 Pop means take a data element off the top of the stack 9/22/2011, Lecture 10 CSC 1254, Fall 2011, Stacks and Queues
Background image of page 11

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

View Full DocumentRight Arrow Icon
12 Pop (cont.) 17 5 11 3 Pop means take a data element off the top of the stack 9/22/2011, Lecture 10 CSC 1254, Fall 2011, Stacks and Queues
Background image of page 12
Image of page 13
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 12/29/2011 for the course CSC 1254 taught by Professor Blanks,l during the Fall '08 term at LSU.

Page1 / 40

Lecture 10 - The Stack and Queue Types - The Stack and...

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

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