Question: For this assignment, you will implement the find() (at list 129) and replaceAt() (at line 123) methods of the List class that we looked at

For this assignment, you will implement the find() (at list 129) and replaceAt() (at line 123) methods of the List class that we looked at in class.

The public int find(Object val) method searches the linked list looking for an item that matches the Object in val. If it finds the object, it returns the index at which it was found in the list. If not, it return -1, indicating that the value is not on the list.

The public Object replaceAt(Object val, int idx) replaces the object at index idx with the Object in val and returns the Object that was replaced. If idx is not valid, the method returns null.

For example, given the list ll:

<1:[3] | 2:[6] | 3:[9] | 4:[12] | 5:[15] | 6:[18] | 7:[21] | 8:[24] | 9:[27] | 10:[30]>

where the numbers before the colons the indices and the numbers in brackets are Integer objects, then

ll.replaceAt(222, ll.size())

changes the list ll to

<1:[3] | 2:[6] | 3:[9] | 4:[12] | 5:[15] | 6:[18] | 7:[21] | 8:[24] | 9:[27] | 10:[222]>

The call

ll.find(222)

returns

10

while the call

ll.find(223)

returns

-1

subject: computer science and fundamentals


Step by Step Solution

3.46 Rating (159 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here is an implementation of the find and replaceAt methods for the List class public class List oth... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Computer Engineering Questions!