Question: please use these two files.. // --------------------------------------------------------------- // MergeSort.java // --------------------------------------------------------------- public class MergeSort { private int[] array; private int[] tempMergArr; private int length; public

 please use these two files.. // --------------------------------------------------------------- // MergeSort.java // --------------------------------------------------------------- please use these two files..

// --------------------------------------------------------------- // MergeSort.java // ---------------------------------------------------------------

public class MergeSort {

private int[] array; private int[] tempMergArr; private int length;

public static void main(String a[]){

int[] inputArr = {45,23,11,89,77,98,4,28,65,43};

// for(int i : inputArr){ // System.out.print(i + " ");} MergeSort ms = new MergeSort(); ms.sort(inputArr);

for(int i : inputArr){ System.out.print(i + " "); } }

public void sort(int inputArr[]) { this.array = inputArr; this.length = inputArr.length; this.tempMergArr = new int[length]; doMergeSort(0, length - 1); }

private void doMergeSort ( int lowerIndex, int higherIndex ) { // for(int i : tempMergArr){ // System.out.print(i + " "); } // if ( lowerIndex

int middle = lowerIndex + (higherIndex - lowerIndex) / 2; // Below step sorts the left side of the array

doMergeSort ( lowerIndex, middle ); // Below step sorts the right side of the array

doMergeSort( middle + 1, higherIndex ); // Now merge both sides

mergeParts( lowerIndex, middle, higherIndex ); } }

private void mergeParts(int lowerIndex, int middle, int higherIndex) {

for ( int i = lowerIndex; i

int i = lowerIndex; int j = middle + 1; int k = lowerIndex;

while ( i

while (i

} }

// --------------------------------------------------------------- // QuickSort.java // ---------------------------------------------------------------

public class QuickSort {

private int array[]; private int length;

public void sort(int[] inputArr) {

if ( inputArr == null || inputArr.length == 0 ) return;

this.array = inputArr; length = inputArr.length; quickSort( 0, length - 1 ); }

private void quickSort ( int lowerIndex, int higherIndex ) {

int i = lowerIndex; int j = higherIndex; // calculate pivot number, I am taking pivot as middle index number int pivot = array[lowerIndex+(higherIndex-lowerIndex)/2]; // Divide into two arrays

while ( i

while ( array[j] > pivot ) { j--; }

if ( i

if ( i

private void exchangeNumbers( int i, int j ) { int temp = array[i]; array[i] = array[j]; array[j] = temp; }

public static void main ( String a[] ){

QuickSort sorter = new QuickSort();

int[] input = {24,2,45,20,56,75,2,56,99,53,12};

sorter.sort(input);

for(int i:input){ System.out.print(i + " "); } } }

Implement the recursive algorithm for the merge sort. Complete the implementation of quick sort by implementing the method partition

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!