Question
This is Java Code of MergeSort. I tried to run it but it throws this errors Exception in thread main java.lang.ArrayIndexOutOfBoundsException: 7 at Merge.Merge(Merge.java:31) at
This is Java Code of MergeSort. I tried to run it but it throws this errors
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 7 at Merge.Merge(Merge.java:31) at Merge.MergeSort(Merge.java:11) at Merge.MergeSort(Merge.java:10) at Merge.main(Merge.java:55)
Please Help me to fix it. Below are the code
import java.util.Arrays;
public class Merge {
public static void MergeSort( int [] A, int p, int r){ if( p < r ) { int q = (int) Math.floor((p+r)/2); MergeSort(A,p,q); MergeSort(A,q + 1,r); Merge(A,p,q,r); } }
public static void Merge( int [] A, int p,int q, int r){ int n1 = q - p +1; int n2 = r - q; int [] left= new int [n1+1 ]; int [] right = new int [n2+1 ]; for(int i = 0;i
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started