Question: Java Programming I have a bug in my code. I think it has to do something with's my teacher's NOTE or maybe my for loop

Java Programming

I have a bug in my code. I think it has to do something with's my teacher's NOTE or maybe my for loop is wrong. Fix the bug in my code and make it run. Make sure you format your code. Thanks

. Here's my teacher's algorithm:

Java Programming I have a bug in my code. I think it

Code:

import java.io.File; 7 import java.util.Scanner; 8 import java.util.Arrays; 9 import java.io.FileNotFoundException; 10 11 public class mergeSort 12 13 { 14 // sorting the merge 15 16 public static void merge_sort(int[] arr, int [] temp, int p, int r) { 17 if (p q) { 47 arr[k] = temp [j]; 48 j = j + 1; 49 } 50 //right half empty, copy from the left 51 else if (j > r) { 52 arr[k] = temp[j]; 53 i = i + 1; 54 } 55 //copy from the right 56 else if (temp[j] // NOTE: You have to allocate temp array in the main method and copy the original input array A to // the temp array before invoking merge sort in the main method MERGE-SORT (A, temp, p,r) If p q // left half empty, copy from the right A[k] - templl j j+1 else ifja r right half empty, copy from the left A[k] - temp[i] else if temp[j]

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!