Important Notice:

Practice-It will be discontinued as of November 1st, 2024. After this date, the website will remain online for a transitional period, but login will be restricted to University of Washington NetID authentication. This marks the next phase towards the platform's full retirement. Thank you for your use and support of the application over the years.

If you are looking for an alternative, a similar tool, CodeStepByStep, was developed independently by the original author of Practice-It, and is available at codestepbystep.com**

logo Practice-It logo

reorder

Related Links:
Author: Robert Baxter

Write a method reorder that could be added to the LinkedIntList class from lecture and section. The method rearranges a list of integers into sorted order assuming already sorted by absolute value. Suppose a LinkedIntList variable list stores the following values:

[0, -3, 3, -5, 7, -9, -10, 10, -11, -11, -11, 12, -15]

Notice that the values are in sorted order ignoring the sign of each value. The call list.reorder(); should reorder the values into sorted, non-decreasing order (including sign).

[-15, -11, -11, -11, -10, -9, -5, -3, 0, 3, 7, 10, 12]

Because the list is sorted by absolute value, you can solve this problem very efficiently. Your solution is required to run in O(N) time where N is the length of the list.

Assume that we are adding this method to the LinkedIntList class as seen in lecture and as shown below. You may not call any other methods of the class to solve this problem, you may not construct any new nodes, and you may not use any auxiliary data structures to solve this problem (such as an array, ArrayList, Queue, String, etc.). You also may not change any data fields of the nodes. You must solve this problem by rearranging the links of the list.

public class LinkedIntList {
    private ListNode front;
    ...
}

public class ListNode {
    public int data;
    public ListNode next;
    ...
}
Type your solution here:


This is a partial class problem. Submit code that will become part of an existing Java class as described. You do not need to write the complete class, just the portion described in the problem.

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.