Java Reference
In-Depth Information
last node in the linked list. Draw a Ȓbefore/afterȓ diagram of the changes of
the links in a linked list under the addLast and removeLast methods.
΢΢Exercise R15.7. The linked list class in the Java library supports
bidirectional iterators. To go backward efficiently, each Node has an
added reference, previous , to the predecessor node in the linked list.
Draw a Ȓbefore/afterȓ diagram of the changes of the links in a linked list
under the addFirst and removeFirst methods that shows how the
previous links need to be updated.
692
693
΢΢Exercise R15.8. What advantages do lists have over arrays? What
disadvantages do they have?
΢΢Exercise R15.9. Suppose you needed to organize a collection of telephone
numbers for a company division. There are currently about 6,000
employees, and you know that the phone switch can handle at most 10,000
phone numbers. You expect several hundred lookups against the collection
every day. Would you use an array or a list to store the information?
΢΢Exercise R15.10. Suppose you needed to keep a collection of
appointments. Would you use a list or an array of Appointment objects?
΢ Exercise R15.11. Suppose you write a program that models a card deck.
Cards are taken from the top of the deck and given out to players. As cards
are returned to the deck, they are placed on the bottom of the deck. Would
you store the cards in a stack or a queue?
΢ Exercise R15.12. Suppose the strings ÐAÑ È ÐZÑ are pushed onto a
stack. Then they are popped off the stack and pushed onto a second stack.
Finally, they are all popped off the second stack and printed. In which order
are the strings printed?
Additional review exercises are available in WileyPLUS.
PROGRAMMING EXERCISES
΢΢Exercise P15.1. Using only the public interface of the linked list class,
write a method
Search WWH ::




Custom Search