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
Step: 1
Here is an implementation of the find and replaceAt methods for the List class public class List oth...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started