Exercise 15. Stacks and Queues
When working with data structures you’ll oftentimes encounter a structure that is similar to another. A Stack is similar to a SingleLinkedList from Exercise 13, and a Queue is similar to a DoubleLinkedList from Exercise 14. The only difference is a Stack and a Queue restrict the possible operations to simplify how they are used. This helps reduce defects since you can’t accidentally use the Stack like a Queue and cause problems. In a Stack, the nodes are “pushed” onto the “top” and then “popped” from the top as well. With a Queue, the nodes are shifted to the “tail” and then unshifted off the “head” of the structure. Both of these operations are simply simplifications of the SingleLinkedList and DoubleLinkedList ...
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