Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 A Beginners Guide

Authors: Andy Oppel

1st Edition

007160846X, 978-0071608466

More Books

Students also viewed these Databases questions

Question

n How to price the risk attaching to an individual asset

Answered: 1 week ago