Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA have to do copyList() can anyone help please? 2. (2.5 points) Starting from

ID: 3855452 • Letter: J

Question

JAVA have to do copyList() can anyone help please?

2. (2.5 points) Starting from the implementation of LinkedList300 from the accompanying hw4.jar file, complete a method for this class called copyList. It retums a new LinkedList300 item which contains the same data as the old linked list, in the same sequence. The TestHW4 class implemented, the ouptput should be listl is [1, 2, 3] list2 is [l,2, 3] listl is [,2, 3, 4] list2 is [0, 1, 2, 3] You will receive 1 point of extra credit if you write this method such that it runs in en) time, where n is the number of items in the linked list.

Explanation / Answer

The answer is as follows:

The code for copyList is as follows:

public LinkedList<T> copyList() {

     LinkedList<T> List1 = new LinkedList<T>();
     Node<T> current;
     current = first.next;
     while (current != last){
         List1.add(current.item);
         current = currents.next;
     }
     return List1;
}