John Paterson wrote:
The correct answer is 'd. LinkedList' and the explanation for the answer says:
"When objects are frequently inserted and deleted from the middle of the sequence, LinkedList gives the best performance."
I am a little puzzled by this explanation. In the Kathy Sierra book it is mentioned:
"LinkedList: Good for adding elements to the ends, i.e., stacks and queues."
Why this difference? Hope someone can help. Thanks.
Based on the context of the question, the explanation is correct. Linked lists are good for inserting and deleting (anywhere) in the list. However, it is not very good at getting to a particular member in the middle of the list -- which the question carefully avoided mentioning. The question did not mention that you need to have an iterator at the point that you want to insert or delete.
As for the book, that is correct too. A linked list do work great for stacks and queues. And it is also easy to add elements to the ends.