This assignment simply requests that you take the quicksort algorithm that you have been working with and make it generic. You are to demonstrate the effectiveness of your work by defining the main method that passes a list of Integers, Doubles, and Strings and sorts them all.
NOTE: this is the code, please tell me which one of the blocks of code does.
import java.util.*;
public class Driver{
public static <T extends Comparable<T>> void quickSort(T[] data, int a, int b) {
if (a < b) {
int i = a, j = b;
T x = data[(i + j) / 2];
do {
while (data[i].compareTo(x) < 0) i++;
while (x.compareTo(data[j]) < 0) j--;
if ( i <= j) {
T tmp = data[i];
data[i] = data[j];
data[j] = tmp;
i++;
j--;
}
} while (i <= j);
quickSort(data, a, j);
quickSort(data, i, b);
}
}
public static void main(String args[]) {
String[] names = {"John", "Paul", "Anna", "Rock"};
Driver.<String>quickSort(names, 0, names.length-1);
for(String i: names) {
System.out.println(i);
}
}
}
import java.util.*;
public class Driver {
public static <T extends Comparable<T>> void quickSort(T[] data, int a, int b) {
if (a < b) {
int i = a, j = b;
T x = data[(i + j) / 2];
do {
while (data[i].compareTo(x) < 0) i++;
while (x.compareTo(data[j]) < 0) j--;
if (i <= j) {
T tmp = data[i];
data[i] = data[j];
data[j] = tmp;
i++;
j--;
}
} while (i <= j);
quickSort(data, a, j);
quickSort(data, i, b);
}
}
public static void main(String args[]) {
String[] names = {"John", "Paul", "Anna", "Rock"};
Driver.quickSort(names, 0, names.length - 1);
System.out.println("Strings in sorted order are");
for (String i : names) {
System.out.println(i);
}
System.out.println();
Integer[] integers = {4, 0, 1, 2, 9, 5};
Driver.quickSort(integers, 0, integers.length - 1);
System.out.println("Integers in sorted order are");
for (Integer i : integers) {
System.out.println(i);
}
System.out.println();
Double[] doubles = {9.5, 2.0, 5.6, 8.2, 3.7};
Driver.quickSort(doubles, 0, doubles.length - 1);
System.out.println("Doubles in sorted order are");
for (Double i : doubles) {
System.out.println(i);
}
System.out.println();
}
}

This assignment simply requests that you take the quicksort algorithm that you have been working with...
6. (4 points) The following code for insertion sort has been modified to print out the sorted component of the array during the sort. What will be the output of running the main method of the following code? Try to trace by hand and then verify by executing the code public class Insertion ( public static void sort (String[] a) f int n- a.length; for (int i-1; i < n; i++) f for (int j i; j 0; j--) if...
Need to code the HeapSort Algorithm in java. Most of the code is already done just need to code the "heapify" part of the heapsort algorithm. My heapify code is in bold below called "sink", but when I run it it gives me 2 errors with the string compare part saying: WordCountHeap.java:61: error: cannot find symbol if(l < k && String.Compare(pq[l], pq[n]) < 0) ^ symbol: method Compare(String,String) location: class String Please fix the code and the "heapify"...
USING JAVA GIVEN THE CODE BELOW Choose the players to play each other in the rounds (there would be 3 rounds, quarter-final, semi-final and final) from the eligible players (players that lose a game are eliminated). For each round the highest ranked player plays the lowest ranked one i.e., in quarter-final round, player ranked 1 plays player ranked 8, player ranked 2 plays player ranked 7 and so on. Report the winner of each match, simulating using random values of...
Below I have my 3 files. I am trying to make a dog array that aggerates with the human array. I want the users to be able to name the dogs and display the dog array but it isn't working. //Main File import java.util.*; import java.util.Scanner; public class Main { public static void main(String[] args) { System.out.print("There are 5 humans.\n"); array(); } public static String[] array() { //Let the user...
Modify the sorts (selection sort, insertion sort, bubble sort, quick sort, and merge sort) by adding code to each to tally the total number of comparisons and total execution time of each algorithm. Execute the sort algorithms against the same list, recording information for the total number of comparisons and total execution time for each algorithm. Try several different lists, including at least one that is already in sorted order. ---------------------------------------------------------------------------------------------------------------- /** * Sorting demonstrates sorting and searching on an...
please evaluate the following code. this is JAVA a. class Car { public int i = 3; public Car(int i) { this.i = i; } } ... Car x = new Car(7), y = new Car(5); x = y; y.i = 9; System.out.println(x.i); b. class Driver { public static void main(String[] args) { int[] x = {5, 2, 3, 6, 5}; int n = x.length; for (int j = n-2; j > 0; j--) x[j] = x[j-1]; for (int j...
7.11 LAB: Sorting user IDs Given a main() that reads user IDs (until -1), complete the quicksort() and partition() methods to sort the IDs in ascending order using the Quicksort algorithm, and output the sorted IDs one per line. Ex. If the input is: kaylasimms julia myron1994 kaylajones -1 the output is: julia kaylajones kaylasimms myron1994 Code: import java.util.Scanner; import java.util.ArrayList; public class UserIDSorting { // TODO: Write the partitioning algorithm - pick the middle element as the // pivot,...
When my quicksort is passed a large array of words, i
get a stackOverflow error, what can i do so it doesnt end up in an
infinite recursive loop
public void quickSort(String[] words, int low, int high) { if(low high) { int p = partition (words, low, high); quickSort(words, low,--p); quickSort(words, ++p, high); private int partition(String[] words, int low, int high) { int i = low - 1; for(int j = low; j < high; j++) { if(words[j].compareTo(words[high]) < 0)...
import java.util.Arrays; public class lab { public static void main(String args[]) { int arr[] = {10, 7, 8, 9, 1, 5,6,7}; int arr2[] = {9, 8, 7, 6, 5, 4, 3, 2, 1}; int arr3[] = {1, 3, 5, 3, 2, 6, 20}; quicksort(arr,0,arr.length-1); quicksort(arr2,0,arr2.length-1); quicksort(arr3,0,arr3.length-1); System.out.println(Arrays.toString(arr)); System.out.println(Arrays.toString(arr2)); System.out.println(Arrays.toString(arr3)); } private static int partition(int[] items,int low, int high) { int i=0; int j=0;...
Objective: GUI Layout manager Download one of the sample GUI layout program. Use any GUI layout to add buttons to start each sort and display the System.nanoTime in common TextArea panel. The question is a bit confusing so i will try to simplify it. Using the GUI ( I made a unclick able one so you have to make it clickable), allow a user to sort the text file based on what they click on. example: if i click merge...