0

Hello Friends.. need a help with Merge Sort

I tried to implement Merge Sort using Java language..I followed Introduction to Algorithm book for the algorithm.. but the code generates errors.. please can anyone explain this to me.. why these errors pop-up ??

```
package test;
import java.util.Random;
public class mergeSort {
public static void main(String[] args) {
int[] A=new int[20];
Random generator = new Random();
for(int c=0;c<20;c++){
A[c]= generator.nextInt(100);
System.out.print( A[c]+ " ");
}
MyMergeSort sort = new MyMergeSort();
sort.mergeSort(A, 0, 20);
System.out.print( "\n");
for(int c=0;c<20;c++){
System.out.print( +A[c]+ " ");
}
}
}
class MyMergeSort{
void mergeSort(int A[],int p,int r){
int q;
if(p<r){
q= (int) Math.floor((p+r)/2);
try{
mergeSort(A, p, q);
}
catch(Exception e){
System.out.print(e.getMessage()+" one");
}
try{
mergeSort(A, q+1, r);
}
catch(Exception e){
System.out.print(e.getMessage()+" two");
}
try{
merge(A, p, q, r);
}
catch(Exception e){
System.out.print("\n\n\n"+e.getMessage()+" three");
}
}
}
void merge(int A[],int p,int q,int r){
int n1,n2;
int[] L=new int[r];
int[] R=new int[r];
n1 = q-p+1;
n2 = r-q;
int i,j;
for(i=1;i<n1;i++){
L[i]=A[p+i-1];
}
for(j=1;i<n2;i++){
R[j]=A[q+j];
}
L[n1+1]=(int)Double.POSITIVE_INFINITY;
R[n2+1]=(int)Double.POSITIVE_INFINITY;
i=1;
j=1;
for(int k=p;k<p;k++){
if(L[i]<=R[j]){
A[k]=L[i];
i++;
}
else if(A[k]==R[j]){
j++;
}
}
}
}
```

thank you in advance..