Skip to Content
Data Structures and Algorithms in Python
book

Data Structures and Algorithms in Python

by Michael T. Goodrich, Roberto Tamassia, Michael H. Goldwasser
March 2013
Intermediate to advanced
748 pages
21h 42m
English
Wiley
Content preview from Data Structures and Algorithms in Python

Chapter 6

Stacks, Queues, and Deques

images

Contents

6.1 Stacks

A stack is a collection of objects that are inserted and removed according to the last-in, first-out (LIFO) principle. A user may insert objects into a stack at any time, but may only access or remove the most recently inserted object that remains (at the so-called “top” of the stack). The name “stack” is derived from the metaphor of a stack of plates in a spring-loaded, cafeteria plate dispenser. In this case, the fundamental operations involve the “pushing” and “popping” of plates on the stack. When we need a new plate from the dispenser, we “pop” the top plate off the stack, and when we add a plate, we “push” it down on the stack to become the new top plate. Perhaps an even more amusing example is a PEZ® candy dispenser, which stores mint candies in a spring-loaded container that “pops” out the topmost candy in the stack when the top of the dispenser is lifted (see Figure 6.1). Stacks are a fundamental ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Python Data Structures and Algorithms

Python Data Structures and Algorithms

Benjamin Baka
Hands-On Data Structures and Algorithms with Python - Second Edition

Hands-On Data Structures and Algorithms with Python - Second Edition

Dr. Basant Agarwal, Benjamin Baka, David Julian
Data Structures & Algorithms in Python

Data Structures & Algorithms in Python

John Canning, Alan Broder, Robert Lafore

Publisher Resources

ISBN: 9781118290279Purchase bookOtherOther