Question: Improve the efficiency of the get and set methods of Exercise P16.1 by storing (orcaching) the last known (node, index) pair. If n is
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:
![]()
private Node getNode(int n)
Step by Step Solution
3.44 Rating (157 Votes )
There are 3 Steps involved in it
To improve the efficiency of the get and set methods in your linked list by caching the last accessed node you would follow these general steps 1 Add ... View full answer
Get step-by-step solutions from verified subject matter experts
