Join Simon Allardice for an in-depth discussion in this video Using queues for first-in, first-out, part of Foundations of Programming: Data Structures.
- View Offline
The key difference between a stack and a Queue.…Stacks are last in first out LIFO.…Queues are first in first out FIFO.…Think of a line at the bank or the supermarket.…We can add multiple people to the queue.…But when we want to take something from the queue,…they should always be taken from the front of the queue.…One gets taken from the front, the others shuffle up…to the front of the queue and the process continues.…Now, queues are used a lot in programming.…Think of sending jobs to a printer.…
As the printer can only deal with one thing at a time, it has a built in queue.…You queue up multiple jobs for printing, and it will…take those jobs in the order that they were submitted.…First in will be first out.…And queues are very commonly used in multi…threading and concurrency situations to keep track of…what tasks are waiting to be performed and making sure we take them in that order.…Now just as with the stack the idea of a queue as an abstract data type…is that we do not care about the…actual implementation of this data structure behind the scenes.…
Starting with simple ways of grouping data like arrays and structs, together you'll explore gradually more complex data structures, like dictionaries, sets, hash tables, queues and stacks, links and linked lists, and trees and graphs. Simon keeps the lessons grounded in the real world and answers the "why" behind many data-structuring decisions: Why use a hash table? Why is a set useful? Why avoid arrays? When you're finished with the course, you'll have a clear understanding of data structures and understand how to use them in whatever language you're programming in, today or 5 years from now.
- What is a data structure?
- Using C-style structs and arrays
- Sorting and searching arrays
- Working with singly and doubly linked lists
- Using stacks for last-in, first-out (LIFO) structures
- Using queues for first-in, first-out (FIFO) structures
- Working with hash tables
- Understanding binary search trees (BSTs)
- Learning about graphs