Question: JAVA. LinkedList NOT an array. Here are the classes where split() should go (it should go in LinkedIntList()). Below is ListNode() public class ListNode {

 JAVA. LinkedList NOT an array. Here are the classes where split()

JAVA. LinkedList NOT an array. Here are the classes where split() should go (it should go in LinkedIntList()). Below is ListNode()

public class ListNode { public int data; // data stored in this node public ListNode next; // link to next node in the list // post: constructs a node with given data and given link public ListNode(int data, ListNode next) { this.data = data; this.next = next; } // post: constructs a node with given data and null link public ListNode(int data) { this(data, null); } // post: constructs a node with data 0 and null link public ListNode() { this(0, null); } }

Below is LinkedIntList()

public class LinkedIntList implements IntList { private ListNode front; // first value in the list // post: constructs an empty list public LinkedIntList() { front = null; } // post: manipulates the LinkedIntList by swapping the values in a // pair-wise style. Skips a last null value public void switchPairs() // exercise 8 { ListNode current = front; // List will start iterating from front // of the list, making current variable front. while (current.next != null) // until preceding node of current node // IS null, iterate { int temp = current.next.data; // create a temp of the preceding data current.next.data = current.data; // make preceding data equal to // current data current.data = temp; // current data is temp value, which is the value // of a preceding data current = current.next.next; // now iterate from a "non-swapped" value if (current == null) // if end of the list is reached, { break; // break the while loop } } } public void split() { ListNode current = front; ListNode neg = null; ListNode pos = null; ListNode negLast = null; // while loop derived from stackoverflow while(current != null) { ListNode next = current.next; if(current.data  

Please write a comment for every statement as an explanation of why you are putting that statement in that exact location. Thank you so much and ill make sure to rate asap

Write a method called split that rearranges the elements of a list so that all of the negative values appear before all of the nonnegatives. For example, suppose a variable list stores the values [8, 7, -4, 19, 0, 43, -8, -7, 2]. The call of list.split(); should rearrange the list to put the negatives first: [-4, -8, -7, 8, 7, 19, 0, 43, 2]. It doesn't matter what order the numbers are in, only that the negatives appear before the nonnegatives, so this is only one possible solution. You must solve the problem by rearranging the links of the list, not by swapping data values or creating new nodes. You also may not use auxiliary structures like arrays or ArrayLists to solve this problem. Write a method called split that rearranges the elements of a list so that all of the negative values appear before all of the nonnegatives. For example, suppose a variable list stores the values [8, 7, -4, 19, 0, 43, -8, -7, 2]. The call of list.split(); should rearrange the list to put the negatives first: [-4, -8, -7, 8, 7, 19, 0, 43, 2]. It doesn't matter what order the numbers are in, only that the negatives appear before the nonnegatives, so this is only one possible solution. You must solve the problem by rearranging the links of the list, not by swapping data values or creating new nodes. You also may not use auxiliary structures like arrays or ArrayLists to solve this

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!