public void sort(int[] arr) {
sort(arr, new int[arr.length], 0, arr.length);
}
private void sort(int[] arr, int[] holder, int lo, int hi) {
int d = hi - lo;
if (d <= 1) return;
int mid = lo + d/2;
sort(arr, holder, lo, mid);
sort(arr, holder, mid, hi);
merge(arr, holder, lo, mid, hi);
}
private void merge(int[] arr, int[] holder, int lo, int mid, int hi) {
int i = lo;
int j = mid;
for (int k = lo; k < hi; k++) {
if (i == mid) holder[k] = arr[j++];
else if (j == hi) holder[k] = arr[i++];
else if (arr[j] < arr[i]) holder[k] = arr[j++];
else holder[k] = arr[i++];
}
for (int k = lo; k < hi; k++) arr[k] = holder[k];
}