Question: Sorting and Searching Given the following code, implement a recursive mergeSortHelper method below: import java.util.List; import java.lang.Comparable; public class Sorters2120 { public static void bubbleSort(List

Sorting and Searching

Given the following code, implement a recursive mergeSortHelper method below:

import java.util.List; import java.lang.Comparable; public class Sorters2120 {

public static > void bubbleSort(List theList) { int lastToConsider = theList.size(); while (lastToConsider > 1) { for (int j=0; j 0 ) { swap(theList,j,j+1); } } lastToConsider--; } } // End method bubbleSort

private static > void swap(List theList, int i1, int i2) {

T temp = theList.get(i1); theList.set(i1,theList.get(i2)); theList.set(i2,temp); } // End method swap

public static > void selectionSort(List theList) { // Loop over theList.size() - 1 for (int index = 0; index < theList.size() - 1; index++) { int min = index; // First index // Loop to find minimum for (int scan = index + 1; scan < theList.size(); scan++) if (theList.get(scan).compareTo(theList.get(min)) < 0) min = scan; // Find minimum

swap(theList, min, index); // Swap the values } } // End method selectionSort

public static > void mergeSort(List theList) { recursiveMergeSortHelper(theList,0,theList.size()); } // End method mergeSort

private static > void recursiveMergeSortHelper(List theList, int first, int last) {

// stubbed

} // End method recursiveMergeSortHelper

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!