Question: 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.
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.
Step by Step Solution
3.49 Rating (162 Votes )
There are 3 Steps involved in it
public void split if front null ListNode cur... View full answer
Get step-by-step solutions from verified subject matter experts
