Respuesta :
Answer:
Explanation:
The following method will take in a LinkedList as an argument and split it, adding only the first element to the firstItemList and the rest of the elements to listRemainder. The firstItemList and ListRemainder may have to be changed to static in order for the method to be able to access them, or add a setter/getter method for them.
public static void split(LinkedList list) {
firstItemList = new LinkedList();
listRemainder = new LinkedList();
firstItemList.add(list.peek());
list.pop();
listRemainder = list;
}

The complete java code for the Runner class can be defined as follows:
Java Code:
public class Runner<T>//defining a class Runner
{
private LinkedList<T> firstItemList;//defining LinkedList type array variable that is firstItemList
private LinkedList<T> ListRemainder;//defining LinkedList type array variable that is ListRemainder
public Runner()//defining default constructor
{
firstItemList=null;//holding null value in list type variable
ListRemainder=null;//holding null value in list type variable
}
public void split(LinkedList<T> WholeLinkedList)//defining a method split that takes a list in parameter
{
if(WholeLinkedList==null)//defining if block that checks parameter variable value equal to null
return;//using return keyword
firstItemList=WholeLinkedList;//holding parameter variable value in firstItemList
ListRemainder=WholeLinkedList.next;//holding parameter variable next value in ListRemainder
firstItemList.next=null;//holding null value in firstItemList.next element
}
}
Code Explanation:
- Defining a class Runner.
- Inside the class two LinkedList type array variable that is "firstItemList, ListRemainder" is declared.
- In the next step, a default constructor is defined, in which the above variable is used that holds null value in list type variable.
- In the next line, a method "split" is declared in which it accepts "WholeLinkedList" as a parameter.
- Inside this, if a conditional block is defined that checks parameter variable value equal to null if it's true it returns nothing.
- outside the conditional block, it checks the parameter value and holds value in it.
Find out more about the linked list here:
brainly.com/question/23731177
