Question: Write the following two generic methods using quick sort. The first sorts the elements using the Comparable interface, and the second uses the Comparator interface.

Write the following two generic methods using quick sort. The first sorts the elements using the Comparable interface, and the second uses the Comparator interface. Below, you will find and outline of the source code you need to complete this program.

public static >

void quickSort(E[ ] list)

/* Include your code here */

public static void quickSort(E[ ] list,

Comparator comparator)

// Code goes here

Your program should all fit into one file and include the following driver program:

public class FirstName_LastName_Test2 {

public static void main(String[ ] args) {

Integer[ ] list = {2, 3, 2, 5, 6, 1, -2, 3, 14, 12};

quickSort(list);

for (int i = 0; i < list.length; i++) {

System.out.print(list[i] + " ");

}

System.out.println();

Circle[ ] list1 = {new Circle(2), new Circle(3), new Circle(2),

new Circle(5), new Circle(6), new Circle(1), new Circle(2),

new Circle(3), new Circle(14), new Circle(12)};

quickSort(/* You need to include the relevant parameter list here */);

for (int i = 0; i < list1.length; i++) {

System.out.print(list1[i] + " ");

}

}

/* Your other methods

will be included here*/

}

/* Your other classes

all included in the same file */

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 Programming Questions!