Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help fixing this code. The assignment gave us pseudocode that we had to translate to Java. I see a bunch of posts where

I need help fixing this code. The assignment gave us pseudocode that we had to translate to Java. I see a bunch of posts where they turned this into a while loop but I need it to work a close to this as possible. I keep getting an error on for (k = 0;until;end-start){ were it says it's not a statement. I'm being tested on these 3 criteria.

The mergeSort() method handles a sorted array as a parameter and an array with identical elements.

2

The mergeSort() method handles sorting even and odd elements

2

The mergeSort() method handles sorting an empty array and an array with one element.

2

Run ChecksSubmit 0%

public class MergeSort {

// Write your code here

public static void mergeSort(int []array, int start, int end){

if(start < end){

midPoint = (end - start) / 2 + start;

mergeSort(array, start, midPoint);

mergeSort(array, midPoint + 1, start);

merge(array, start, midPoint, end);

}

}

public static void merge(int []array, int start, int middle, int end){

i = start;

j = middle + 1;

arrayTemp = initArrayOfSize(end - start + 1);

for (k = 0;until;end-start){

if (i <= middle && (j > end || array[i] <= array[j])) {

arrayTemp[k] = array[i];

i++;

}

else {

arrayTemp[k] = array[j];

j++;

copyArray(arrayTemp,array,start);

}

}

}

public static void merge(int []array){

merge(array,start, end);

}

public static void main(String[] args) {

/*

* This main method is a stub.

* It does nothing.

* Feel free to write your own code to test your implementation.

* In this case, we have nothing actionable in here, just this comment block, so the JVM should rapidly lose interest and move on to the rest of your code.

*/

}

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

Step: 3

blur-text-image

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

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

=+That is, who are the stakeholders?

Answered: 1 week ago