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:
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
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