Click here to Skip to main content
15,942,580 members
Please Sign up or sign in to vote.
1.24/5 (3 votes)
See more:
Java
private static void merge(Comparable[] a, Comparable[] aux,
int lo, int mid, int hi) {
    for(int k = lo; k <= hi; k++) aux[k] = a[k];
    int i = lo, j = mid + 1;
    for(int k = lo; k <= hi; k++) {
        if(i > mid) 
        else if(j > hi)               
        else if(less(aux[j], aux[i])) 
        else                          
    }
}
public class Merge {
    private static void merge(/*...*/) { /* as before */ }

    private static void sort(Comparable[] a, Comparable[] aux,
                             int lo, int hi) {
        if(hi <= lo) return;
        int mid = lo + (hi - lo) / 2;
        sort(a, aux, lo, mid);
        sort(a, aux, mid+1, hi);
        merge(a, aux, lo, mid, hi);
    }

    public static void sort(Comparable[] a) {
        Comparable[] aux = new Comparable[a.length];
        sort(a, aux, 0, a.length - 1);
    }
}


What I have tried:

I tried reviewing the code but I still can't figure out why it would'nt run. Please help
Posted
Updated 19-Jan-23 23:33pm
v2

Mostly because it won't compile.
Java
for(int k = lo; k <= hi; k++) {
    if(i > mid)
    else if(j > hi)
    else if(less(aux[j], aux[i]))
    else
}
None of your conditional code contains any executable lines after the condition: That won't compile at all.
You have this:
Java
if (condition)
else if (other condition)
else
And you need this:
Java
if (condition)
   something to do when it is true
else if (other condition)
   something to do when it is true
else
   something to do when neither was true
 
Share this answer
 
v2
Comments
CPallini 19-Jan-23 2:18am    
5.
Given all these Java questions you have posted, I would advise you to go to Java Tutorials Learning Paths[^], and spend some time studying the language.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900