D
D
Den4_x2019-08-01 22:39:25
Java
Den4_x, 2019-08-01 22:39:25

How does this merge algorithm (mergeSort) work?

public static void mergeSort(int[] array, int low, int high) {
        if (high - low < 2) {
            return;
        }
        int mid = (low + high) >>> 1;
        mergeSort(array, low, mid);
        mergeSort(array, mid, high);
        int[] b = Arrays.copyOfRange(array, low, mid);
        for (int i = low, j = mid, k = 0; k < b.length; i++) {
            if (j == high || b[k] <= array[j]) {
                array[i] = b[k++];
            } else {
                array[i] = array[j++];
            }
        }
    }

I understand how it works visually, but in code, it is very difficult for me to navigate here. Please, if you have the time and energy, please explain in detail what and how it works here, I will be very GRATEFUL to you.
Thanks in advance for your ANSWER!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Skusnov, 2019-08-02
@AlexSku

Item 2 German dance
https://forany.xyz/a-370

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question