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

In this assignment, we need to split a linked list into two sublists of Almost E

ID: 3660908 • Letter: I

Question

In this assignment, we need to split a linked list into two sublists of Almost Equal Sizes. Please do the following two steps:

a. Add the method splitMid to the class LinkedListClass (LinkedListClass.java) as follows: public void splitMid(LinkedListClass sublist); //this method splits the given list into two sublists of (almost) equal sizes. //Precondition: the list must exist. //Postcondition: first points to the first node, and the last point to the last node of the first //sublist. Sublist.first points to the first node, and sublist.last points to this last node of the //second sublist. Consider the following statements: UnorderedLinkedList myList; UnorderedLinkedList subList; Suppose myList points to the list with elements 10, 20, 30, 40, and 50 (in this order). The statement myList.splitMid(subList); shall split mylist into two sublists: myList points to the list with elements 10, 20, and 30, and sublist points to the sublist with elements 40 and 50.

b. Write a program to test your method using the class UnorderedLinkedList.

Explanation / Answer

import java.util.LinkedList; public class SplitLinkedList { public void splitMid(LinkedList sublist) { Node midPoint = nodeBefore.next; // get the midpoint LinkedList n = new LinkedList(); n.head = midPoint; // head pointer for the second linked list for(int i = 0; i