| |
The problem is: "create a static java method that take an array of integers. The method should sort the integers from lowest to highest in any algorithm that takes n logn n time. The method should return a linked list of the sorted numbers."
Writing code to sort array is easy. There's quicksort, mergesort, or heapsort. The only way I know to return a linked link, this involves an inner class. My plan,
public static LinkedList sort (int [] numbers) { convertToLinkedList(internalSort(numbers)); public static int[] internalSort(numbers) { // return list of sorted numbers } public static LinkedList convertToLinkedList(int [] numbers) { // convert array argument to LinkedList type } }
To clarify, I'm not asking for sorting code. The problem is structuring the conversion of array into LinkedList. Is there a way to do this sort task without inner classes? |