Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Corporate Finance

Authors: Stephen Ross, Randolph Westerfield, Jeffrey Jaffe

10th edition

978-0077511388, 78034779, 9780077511340, 77511387, 9780078034770, 77511344, 978-0077861759

More Books

Students also viewed these Computer Engineering questions

Question

Define induction and what are its objectives ?

Answered: 1 week ago

Question

Discuss the techniques of job analysis.

Answered: 1 week ago

Question

How do we do subnetting in IPv6?Explain with a suitable example.

Answered: 1 week ago

Question

Explain the guideline for job description.

Answered: 1 week ago

Question

What is job description ? State the uses of job description.

Answered: 1 week ago