Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

merge sort algorithm in java short answer

public static void mergeSort(int[] a, int n) {
    if (n < 2) {
        return;
    }
    int mid = n / 2;
    int[] l = new int[mid];
    int[] r = new int[n - mid];

    for (int i = 0; i < mid; i++) {
        l[i] = a[i];
    }
    for (int i = mid; i < n; i++) {
        r[i - mid] = a[i];
    }
    mergeSort(l, mid);
    mergeSort(r, n - mid);

    merge(a, l, r, mid, n - mid);
}
Comment

PREVIOUS NEXT
Code Example
Java :: Uri/Beecrowd Problem no - 1185 Solution in Java 
Java :: leerzeichen ersetzen java 
Java :: Automatic Code Completion in NetBeans 
Java :: SpringBootStarter maven dependency 
Java :: how to enable/disable wifi or internet 
Java :: class generique java 
Java :: Java Add elements to a LinkedList 
Java :: all GlideException#logRootCauses(String) for more detail Cause (1 of 1): class javax.net.ssl.SSLPeerUnverifiedException: Hostname 
Java :: Reference in java equal operator 
Java :: java print line 
Java :: java declare 2d array with values 
Java :: validate data type in request body spring validation 
Java :: httpsession vs cookie servlet 
Java :: Execute method on load 
Java :: model mapper with Page 
Java :: java dictionary array initialization 
Java :: is overriding only works with inherited methods? 
Java :: null pointer exception during registering user to the firebase 
Java :: jLabel copy 
Java :: javax big int validation in spring boot 
Java :: findbyname in jpa 
Java :: how to declare and allocate memory to array in java 
Java :: jaggies 
Java :: read java reader 
Java :: How to disable special characters on keyboard in android 
Java :: hash tree in java 
Java :: testng with cucumber 
Java :: java length of array 
Java :: java string stringbuilder remove trailing comma 
Java :: synchronized block in java 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =