Question: 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

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!