Exercises
The following exercises provide you with the opportunity to practice with stacks and queues. The solutions to these exercises are found in the section Chapter 9.
-
If you were writing software for a call center that places callers on hold and then assigns them to “the next available representative,” would you use a stack or a queue?
-
If you pushed numbers onto a stack in the following order: 1, 2, 3, 4, 5, 6, and then popped two items, which number would you be able to read from the stack?
-
If you inserted numbers into a queue in the following order: 1, 2, 3, 4, 5, 6, and then dequeued two items, which number would you be able to read from the queue?
-
Write a function that uses a stack to reverse a string. (For example, "abcde" would ...
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