{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Lecture 10 - The Stack and Queue Types

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

Info icon This preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
The Stack and Queue Types Lecture 10 Hartmut Kaiser [email protected] http://www.cct.lsu.edu/˜ hkaiser/fall_2011/csc1254.html
Image of page 1

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

View Full Document Right 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
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
Image of page 3

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

View Full Document Right 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
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
Image of page 5

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

View Full Document Right 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
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
Image of page 7

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

View Full Document Right 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
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
Image of page 9

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

View Full Document Right 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
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
Image of page 11

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

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern