Implement the sort method of the merge sort algorithm without recursion, where the length of the array is an arbitrary number. Keep merging adjacent regions whose size is a power of 2, and pay special attention to the last area whose size is less.
Complete the following file:
Use the following file:
MergeSorterTester.java
import java.util.Arrays; /** This program tests the non-recursive merge sort algorithm. */ public class MergeSorterTester { public static void main(String[] args) { int[] a = new int[20]; for (int i = 0; i < 20; i++) a[i] = 100 - (8 - i)*(8 - i); MergeSorter sorter = new MergeSorter(a); sorter.sort(); System.out.println(Arrays.toString(a)); System.out.println("Expected: [-21, 0, 19, 36, 36, 51, 51, 64, 64, 75, 75, 84, 84, 91, 91, 96, 96, 99, 99, 100]"); } }