Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help implementing this method. All the methods that are in the interface are already implemented. Need help with the last one in both classes

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Need help implementing this method. All the methods that are in the interface are already implemented. Need help with the last one in both classes ArrayList and Linked List 3. Consider a member method reverse() for the List ADT that returns a new List with the elements in reversed order. For example if a List L-(Bob, Mel, Ron, il Ron), then a call to Lreverse will return a new list M = (Ron, Jil, Ron, Mel, Bob). The old list Lis not affected. The prototype for the method is a follows: public Listreversel Add this method to the interface and implement for the ArrayList and LinkedList classes. The method returns an empty list if the list Lis empty. @Override public List reverse() { 2080 209 210 211 212 return null; public interface List extends Iterable { public void add(E obj); public void add(int index, E obj); public boolean remove(E obj); public boolean remove(int index); public int removeAll(E obj); public E get(int index); public E set(int index, E obj); public E first(); public E last(); public int firstIndex(E obj); public int lastIndex(E obj); public int size(); public boolean isEmpty(); public boolean contains(E obj); public void clear(); public int replaceAll (E e, Ef); public List reverse(); 19 21 22 ) 3 import java.util.Iterator; 8 public class ArrayList implements List { // private fields private E elements[]; private int currentSize; 8. public class LinkedList implements List { private class Node { private E value; private Node next; public Node(E value, Node next) { this.value = value; this.next = next; public Node (E value) { this(value, null); // Delegate to other constructor public Node() { this(null, null); // Delegate to other constructor public E getValue() { return value; public void setValue(E value) { this.value = value; public Node getNext() { return next; public void setNext(Node next) { this.next = next; public void clear() { value = null; next = null; } // End of Node class private class ListIterator implements Iterator { private Node nextNode; public ListIterator() { nextNode = header.getNext(); @Override public boolean hasNext() { return nextNode != null; @Override public E next() { if (hasNext()) { E val = nextNode.getValue(); nextNode = nextNode.getNext(); return val; ww else throw new NoSuchElementException(); } // End of ListIterator class 0 von w Il private fields private Node header; private int currentSize

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

Microsoft Visual Basic 2008 Comprehensive Concepts And Techniques

Authors: Gary B. Shelly, Corinne Hoisington

1st Edition

1423927168, 978-1423927167

More Books

Students also viewed these Databases questions

Question

6.15 Identify psychological risk factors in coronary heart disease.

Answered: 1 week ago

Question

Does it avoid using personal pronouns (such as I and me)?

Answered: 1 week ago

Question

Does it clearly identify what you have done and accomplished?

Answered: 1 week ago