A Common-Sense Guide to Data Structures and Algorithms, Second Edition, 2nd Edition
by Jay Wengrow
Chapter 9
These are the solutions to the exercises found in the section, Exercises. The solutions provided here are in Ruby, but you can find the solutions in JavaScript and Python in the code download.[9]
-
Presumably, we’d want to be nice to the callers and answer their phone calls in the order in which they were received. For this, we’d use a queue, which processes data FIFO (First In, First Out).
-
We’d be able to read the 4, which is now the top element in the stack. This is because we’ll have popped the 6 and the 5, which were previously sitting on top of the 4.
-
We’d be able to read the 3, which is now at the front of the queue, after having dequeued the 1 and the 2.
-
We can take advantage of the stack because of the fact that we pop each ...
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.
Read now
Unlock full access