A Critique of the Proposed National Education Policy Reform
please help finish sorting methods- import java-util-Arrays- import ja.pdf
1. please help finish sorting methods:
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.File;
import java.util.Scanner;
public class SortTimes
{
/* convert nanos to seconds */
static final double ONE_BILLION = 1_000_000_000.;
/* sizes of input range should range up to 512k elements */
static int[] sizes = new int[32];
public static void main(String[] args) throws Exception
{
int sIdx = 0;
long startTime;
long endTime;
double time;
int size = 128*1024/sizes.length;
/* let's make size smaller, comment out this next line and see what happens */
size = 16*1024/sizes.length;
for( int i=0; i<sizes.length; i++ ) {
sizes[i] = (i+1)*size;
}
2. Scanner inp = new Scanner(System.in);
System.out.print("What is your last name? ");
String lastName = inp.next();
PrintWriter pw = new PrintWriter(new File(lastName + "_sortTimes.csv"));
pw.println( "Size, BubbleSort, MergeSort, QuickSort, JavaSort, BubbleSort (Sorted Array),
MergeSort (Sorted Array), QuickSort (Sorted Array), JavaSort (Sorted Array)" );
while( sIdx < sizes.length )
{
int[] A = new int[sizes[sIdx]];
int[] B = new int[sizes[sIdx]];
int[] C = new int[sizes[sIdx]];
int[] D = new int[sizes[sIdx]];
int[] E = new int[sizes[sIdx]];
for( int i=0; i<A.length; i++ )
{
A[i] = (int)(Math.random()*sizes[sIdx]*2);
B[i] = A[i];
C[i] = A[i];
D[i] = A[i];
E[i] = 1000; // Array E is used for testing algo on array that is already sorted.
}
System.out.println();
System.out.println("--------------------------------------------------");
System.out.println("Initial Values: ");
6. time = (endTime - startTime) / ONE_BILLION;
System.out.println( "Java's Array sort finished - time = " + time + " seconds." );
pw.println(time);
printArray(E);
System.out.println();
sIdx = sIdx + 1;
}
pw.close();
}
/* prints array or a portion of it if it's too large */
public static void printArray(int[] X)
{
if( X == null ) return;
System.out.print("[ ");
int i=0;
for( ; i<15 && i<X.length; i++ )
{
System.out.print( X[i] + " " );
}
if( i < X.length ) System.out.print("... ");
System.out.println("]");
}
/* Finish Methods Below*/
7. public static void bubbleSort(int[] X)
{
}
public static void mergeSort(int[] X)
{
}
private static void merge(int[] B, int[] C, int[] A )
{
}
/* this is simply the sort used by Arrays class */
public static void javaSort(int[] X)
{
}
public static void quickSort(int[] X)
{
quickSort(X, 0, X.length-1);
}
private static void quickSort(int[] X, int s, int e)
{
// check our stopping condition
// get pivot point from partition method
// call quickSort on left portion and quickSort on right portion
}
8. private static int partition( int[]X, int s, int e )
{
int pivotIdx=s;
return pivotIdx;
}
}