Book: | Cracking Coding Interview 5th edition |
Chapter 3: | Stacks and Queues |
Section: | Implementing a Queue |
Page: | 80 |
The "last" reference should be nullified if a queue becomes empty in the "dequeue" method:
17: first = first.next;
++: if (first == null) last = null;
18: return item;
Otherwise "last" item will not be cleared by the GC on an empty stack.
Received a reply from Gayle via email about accepting the patch: "Great observation. I've updated this for the next printing.".