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
Step: 1
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