Problem

Implement the methods remove and set for the class MyListlterator. These methods should be...

Implement the methods remove and set for the class MyListlterator. These methods should behave as follows:

public void remove()

Removes from the list the last element that was returned by next or previous. This call can be made only once per call to next or previous. It can be made only if the add method in MyListlterator has not been called after the last call to next or previous.

Throws HlegalStateException if neither next nor previous has been called, or if remove or add has been called after the last call to next or previous.

public void set(T item)

Replaces the last element returned by next or previous with the specified element. This call can be made only if neither remove nor add have been called after the last call to next or previous.

Throws IllegalStateException if neither next nor previous has been called, or if remove or add has been called after the last call to next or previous.

Note that remove and set require you to keep track of the state of the iterator; in other words, you must know whedier or not next and previous are called immediately before the use of remove or set. You may also need to keep track of whether previous or next was called last to make sure that the correct element is deleted from or replaced in the list when remove and set are called. You may find it useful to use the variable .lastitemindex to determine if the last call made was to next or previous.

Step-by-Step Solution

Request Professional Solution

Request Solution!

We need at least 10 more requests to produce the solution.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the solution will be notified once they are available.
Add your Solution
Textbook Solutions and Answers Search
Solutions For Problems in Chapter 9
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT