Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions

Question

Have ground rules been established for the team?

Answered: 1 week ago

Question

Is how things are said consistent with what is said?

Answered: 1 week ago

Question

Do you currently have a team agreement?

Answered: 1 week ago