Ho provato ad implementare un Merge-Sort, solo che forse non ho ben capito come funziona e quindi ho sbagliato ad implementarlo....:
codice:
public class MergeSort
{
public static void main(String [] args)
{
int []a={3,6,5,7,9,8,0,5};
int [] S=new int[a.length];
MSort(a,0,a.length-1);
}
public static void merge(int [] a,int []b, int []S, int k)
{
int i=0;
int j=0;
k=0;
while(i<a.length && j<a.length)
{
if(a[i]<b[j])
{
S[k++]=a[i];
i=i++;
}
else if(a[i]>b[j])
{
S[k++]=b[j];
j=j++;
}
}
while(i<a.length)
{
S[k++]=a[i];
i=i++;
}
while(j<b.length)
{
S[k++]=b[j];
j=j++;
}
}
public static int MSort(int [] a,int i, int f)
{
if(i>=f)
{
int m=(i+f)/2;
return MSort(a,i,m);
return MSort(a,m+1,f);
merge(a,b);
}
}
}
Giustamente mi dą errore nel metodo MSort perchč non trova la variabile b.
Perņ non ho capito a questo punto come implementarlo, cioč come faccio a passargli il sottoarray?