Chapter 4
Stacks, Queues, and Deques
IN THIS CHAPTER
Adding data to and removing data from the top of a stack
Adding data to one end of a queue and removing it from the other end
Adding or removing data from either end of a deque
Collections and dictionaries are best suited for storing and organizing data, but they aren’t as useful for retrieving data in an orderly fashion. Trying to keep track of data stored by index numbers or by keys can get cumbersome. As a simpler alternative, computer scientists have created three other data structures: stacks, queues, and deques. Unlike collections or dictionaries, these three data structures are designed for storing and removing data in a predictable order.
A list or an array is much simpler to use but much less flexible than a queue or a stack. Unfortunately, stacks, queues, and deques add greater complexity to your program in exchange for their added flexibility.
Get Beginning Programming All-in-One For Dummies, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.