Improve the efficiency of the get and set methods of Exercise P16.1 by storing (orcaching) the

Question:

Improve the efficiency of the get and set methods of Exercise • P16.1 by storing (or“caching”) the last known (node, index) pair. If n is larger than the last known index, start from the corresponding node instead of the front of the list. Be sure to discard the last known pair when it is no longer accurate. (This can happen when another method edits the list).

Data from exercise P16.1 

Add methods Object get (int n) and void set (int n, Object newElement) to the LinkedList class. Use a helper method that starts at first and follows n links:

image text in transcribed

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  answer-question

Big Java, Enhanced Early Objects

ISBN: 9781119499091

7th Edition

Authors: Cay S Horstmann

Question Posted: