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

public class SLList<E> { private static class Node<E> { private E data; private

ID: 3754970 • Letter: P

Question

public class SLList<E> {

private static class Node<E> {

private E data;

private Node<E> next;

public Node(E data, Node<E> next) {

this.data = data;

this.next = next;

}

}

private Node<E> head = null;

public void add(E data) {

head = new Node(data, head);

}

public SLList methodY(){

SLList list = new SLList();

while (head != null){

list.add(head.data);

head = head.next;

}

return list;

}

}

Assume myList is an instance of SLList , and it refers to the following list of three strings:

AAABBBCCC

Then after the method call myList.methodY();

1.What is the return value of the method? Show your steps.

2.How many strings are in the original list?

3.In general, what is the function of methodY?

Explanation / Answer

1)

Answer: SLList consist of (CONTENTS): AAA->BBB->CCC

Explanation: the methodY()

is declared with return type SLList

hence the return value would be a list of type SLList

NOW

in the method

while loop runs until the head NULL

means we are traversing mylist node by node and copying/adding the data to new list created

so, here we are copying the contents of mylist to new list

that new list is returned

which is AAA->BBB->CCC

2)

Answer: 3 strings

Explanation: already said that myList has AAA->BBB->CCC

which are 3 strings

3)

Answer:

function copies the contents of original list to a new list that is created

and returns the copied list

//pls pls give a thumbs up if you find this helpfull

//thanks