A lesson from the Data Structures module of the bootcamp. About a 10 minute read.
A queue is first in, first out. Swapping a stack for a queue changes nothing about your code except the order things come out, and that one change turns a depth-first search into a breadth-first one, which is how you get shortest paths. It is the smallest edit in this whole subject with the biggest consequence.
A queue is a sequence where you add at the back and remove from the front, so the first thing in is the first thing out. A stack is the memory for nesting. A queue is the memory for FAIRNESS: nothing cuts the line, and everything waits its turn. A deque, pronounced 'deck', is a queue you can add to and remove from at both ends. That makes it a stack and a queue at once, and it is what most languages actually give you.
The rest of this lesson continues with 5 further sections. See the full curriculum.
Browse all 576 practice puzzles