Question: Implement a merge sort algorithm, but without using recursion. Suppose that the size of the field is always a power of 2. First it is
Implement a merge sort algorithm, but without using recursion. Suppose that the size of the field is always a power of 2. First it is necessary to connect adjacent parts of size 1, then adjacent parts of size 2, then adjacent parts of size 4, etc.
public class MergeSorterTester { public static void main(String[] args) { int[] numbers = new int[16]; for (int i = 0; i < 16; i++) { numbers[i] = 100 - (8 - i) * (8 - i); } MergeSorter sorter = new MergeSorter(numbers); sorter.sort(); System.out.println(Arrays.toString(numbers)); System.out.println("Expected results: [36, 51, 51, 64, 64, 75, 75, 84, 84, 91, 91, 96, 96, 99, 99, 100]"); } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
