Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, please answer the Your code here portions. The implementation of the methods contains(E e), get(int index), indexOf(E e), lastIndexOf(E e), and set(int index, E

Hello, please answer the "Your code here" portions.

The implementation of the methods contains(E e), get(int index), indexOf(E e), lastIndexOf(E e), and set(int index, E e) for MylinkedList were omitted from the textbook (Listing 24.6, page 916-918). Based on the contains(E e) and indexOf(E e) given below, please implement get(int index), lastIndexOf(E e), and set(int index, E e).

public boolean contains(Object o) { // Implement it in this exercise Node current = head; for (int i = 0; i < size; i++) { 
 if (current.element.equals(o)) return true; 
 current = current.next; } 
 return false; } 
/** Returns the index of the first * Returns -1 if no match. */ public int indexOf(Object o) { 
 // Implement it in this exercise Node current = head; for (int i = 0; i < size; i++) { 
 if (current.element.equals(o)) return i; 
 current = current.next; } 

return -1; }

matching element in this list. 

/** Return the element from this list at the specified index */ public E get(int index) {

// Your code here! }

/** Returns the index of the last matching element in this list * Returns -1 if no match. */

public int lastIndexOf(Object o) { // Your code here!

}

/** Return and Replace the element at the specified position in this list * with the specified element. */

public E set(int index, E e) { // Your code here!

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions

Question

LO3 Define job design and identify common approaches to job design.

Answered: 1 week ago