Question: 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
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
{
if (current.element.equals(o))
return true;
current = current.next;
}
return false;
}
/** Returns the index of the first matching element in this list.
* Returns -1 if no match. */
public int indexOf(Object o)
{
// Implement it in this exercise
Node current = head;
for (int i = 0; i
if (current.element.equals(o))
return i; current = current.next;
}
return -1;
}
/** 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!
}
head, tail get First remove First LISTING 24.6 My LinkedList.java 1 public class My LinkedList
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
