Java Utililty Methods Merge Sort

List of utility methods to do Merge Sort

Description

The list of methods to do Merge Sort are organized into topic(s).

Method

voidmergesort(double[] a, int[] b, int p, int r)
Arrays with lengths beneath this value will be insertion sorted.
if (p >= r) {
    return;
if (r - p + 1 < SORT_THRESHOLD) {
    insertionsort(a, b, p, r);
} else {
    int q = (p + r) / 2;
    mergesort(a, b, p, q);
...
voidmergeSort(int[] a)
Sorts a given array of integers in ascending order using a recursive merge sort.
merge(a, new int[a.length], 0, a.length - 1);
voidmergeSort(int[] array)
merge Sort
mergeSort(array, 0, array.length - 1);
voidmergeSort(long[] theArray, int nElems)
Mergesort algorithm for an array of long integers.
long[] workSpace = new long[nElems];
recMergeSort(theArray, workSpace, 0, nElems - 1);
voidmergeSort(Object[] src, Object[] dest, int low, int high, int off)
Src is the source array that starts at index 0 Dest is the (possibly larger) array destination with a possible offset low is the index in dest to start sorting high is the end index in dest to end sorting off is the offset to generate corresponding low, high in src
int length = high - low;
if (length < INSERTIONSORT_THRESHOLD) {
    for (int i = low; i < high; i++)
        for (int j = i; j > low && ((Comparable) dest[j - 1]).compareTo(dest[j]) > 0; j--)
            swap(dest, j, j - 1);
    return;
int destLow = low;
...
voidmergeSort(T[] src, T[] dst, int start, int end)
merge Sort
if (start + 1 >= end) {
    if (start >= end)
        return;
    if (src[start].compareTo(src[end]) > 0) {
        swap(src, start, end);
    return;
int middle = (start + end) / 2;
mergeSort(src, dst, start, middle);
mergeSort(src, dst, middle + 1, end);
mergeInOrder(src, dst, start, middle, middle + 1, end);
float[]mergeSorted(float[] a, int alen, float b[], int blen)
merge Sorted
float[] answer = new float[alen + blen];
int i = 0, j = 0, k = 0;
while (i < alen && j < blen) {
    if (a[i] < b[j])
        answer[k++] = a[i++];
    else
        answer[k++] = b[j++];
while (i < alen)
    answer[k++] = a[i++];
while (j < blen)
    answer[k++] = b[j++];
return answer;
Integer[]mergeSortedAaary(int[] a, int[] b)
merge Sorted Aaary
int aL = a.length;
int bL = b.length;
Integer[] c = new Integer[aL + bL];
int countA = 0;
int countB = 0;
int countC = 0;
while (countA < aL || countB < bL) {
    if (countA < aL && countB < bL && a[countA] < b[countB]) {
...
double[]mergeSortedArrays(double[] a, double[] b)
merge Sorted Arrays
double[] answer = new double[a.length + b.length];
int i = 0, j = 0, k = 0;
while (i < a.length && j < b.length) {
    if (a[i] < b[j]) {
        answer[k] = a[i];
        i++;
    } else {
        answer[k] = b[j];
...