import java.lang.*;
/** the class which does the sorting */
public class Sort {
/** temporary variables used in sorting procedues */
long startTime, endTime;
static int pivotValue, left, right, firstRun, secondRun, thirdRun, avgRun;
int qSortCutOff = 0;
int tempValue = 1000000;
boolean useMedOfThree = false;
static Comparable pivot, temp;
//double temp;
Double[] tempArray;
Double[] miniArray, smallArray, mediumArray, largeArray, superArray;
public static final int KID_SIZED = 50;
public static final int SMALL = 100;
public static final int MEDIUM = 500;
public static final int LARGE = 10000;
public static final int SUPER_SIZED = 500000;
/** the method main calls to begin the different sorts */
void timedSort() {
quickSort( miniArray, 0, miniArray.length - 1);
for (int j = 0; j < miniArray.length; j++)
System.out.println( miniArray[j]);
}
/** the simplest implementation of the quickSort algorithm */
static void quickSort( Comparable[] A, int leftBound, int rightBound ) {
if ( leftBound < rightBound ) {
int left = leftBound;
int right = rightBound - 1;
if ( left == right ) {
if (A
/** the class which does the sorting */
public class Sort {
/** temporary variables used in sorting procedues */
long startTime, endTime;
static int pivotValue, left, right, firstRun, secondRun, thirdRun, avgRun;
int qSortCutOff = 0;
int tempValue = 1000000;
boolean useMedOfThree = false;
static Comparable pivot, temp;
//double temp;
Double[] tempArray;
Double[] miniArray, smallArray, mediumArray, largeArray, superArray;
public static final int KID_SIZED = 50;
public static final int SMALL = 100;
public static final int MEDIUM = 500;
public static final int LARGE = 10000;
public static final int SUPER_SIZED = 500000;
/** the method main calls to begin the different sorts */
void timedSort() {
quickSort( miniArray, 0, miniArray.length - 1);
for (int j = 0; j < miniArray.length; j++)
System.out.println( miniArray[j]);
}
/** the simplest implementation of the quickSort algorithm */
static void quickSort( Comparable[] A, int leftBound, int rightBound ) {
if ( leftBound < rightBound ) {
int left = leftBound;
int right = rightBound - 1;
if ( left == right ) {
if (A
.compareTo(A
) > 0 ){
temp = A
temp = A
;
A
A
= A
;
A
A
= temp;
}
return;
}
pivotValue = (int)Math.ceil( ( rightBound - leftBound ) * Math.random()) + left;
//System.out.println(pivotValue);
temp = A[pivotValue];
//System.out.println(rightBound);
A[pivotValue] = A[rightBound];
A[rightBound] = temp;
pivot = A[rightBound];
while ( left <= right ) {
while( left <= right && (A
}
return;
}
pivotValue = (int)Math.ceil( ( rightBound - leftBound ) * Math.random()) + left;
//System.out.println(pivotValue);
temp = A[pivotValue];
//System.out.println(rightBound);
A[pivotValue] = A[rightBound];
A[rightBound] = temp;
pivot = A[rightBound];
while ( left <= right ) {
while( left <= right && (A
.compareTo(pivot) <= 0)) {
left++;
//System.out.println("Incrementing left: " + left );
}
while( right >= left && (A
left++;
//System.out.println("Incrementing left: " + left );
}
while( right >= left && (A
.compareTo(pivot) >= 0))
right--;
if (left < right) {
temp = A
right--;
if (left < right) {
temp = A
;
A
A
= A
;
A
A
= temp;
}
}
temp = A
}
}
temp = A
;
A
A
= A[rightBound];
A[rightBound] = temp;
quickSort(A, leftBound, left - 1);
quickSort(A, left + 1, rightBound);
}
}
/** the implementation of the insertionSort algorithm */
static void insertionSort( Comparable A[], int leftBound, int rightBound ) {
}
/** defines the point at which insertionSort will be used to sort */
void setInsertionSortThreshhold( int threshhold ) {
qSortCutOff = threshhold;
}
/** defines whether to use the median of three method of choosing a pivot or not */
void setMedianOfThree( boolean flag ) {
useMedOfThree = flag;
}
/** creates randomized arrays of various sizes */
void makeArrays() {
miniArray = new Double[KID_SIZED];
for( int j = 0; j < miniArray.length; j++ )
miniArray[j] = new Double( Math.ceil( tempValue * Math.random() ) );
smallArray = new Double[SMALL];
for( int j = 0; j < smallArray.length; j++ )
smallArray[j] = new Double( Math.ceil( tempValue * Math.random() ) );
mediumArray = new Double[MEDIUM];
for( int j = 0; j < mediumArray.length; j++ )
mediumArray[j] = new Double( Math.ceil( tempValue * Math.random() ) );
largeArray = new Double[LARGE];
for( int j = 0; j < largeArray.length; j++ )
largeArray[j] = new Double( Math.ceil( tempValue * Math.random() ) );
superArray = new Double[SUPER_SIZED];
for( int j = 0; j < superArray.length; j++ )
superArray[j] = new Double( Math.ceil( tempValue * Math.random() ) );
}
/** launches the sorting program */
public static void main( String[] args ) {
Sort sortQuick = new Sort();
sortQuick.makeArrays();
sortQuick.timedSort();
//System.out.println(sortQuick.miniArray[KID_SIZED-1].toString());
}
}
A[rightBound] = temp;
quickSort(A, leftBound, left - 1);
quickSort(A, left + 1, rightBound);
}
}
/** the implementation of the insertionSort algorithm */
static void insertionSort( Comparable A[], int leftBound, int rightBound ) {
}
/** defines the point at which insertionSort will be used to sort */
void setInsertionSortThreshhold( int threshhold ) {
qSortCutOff = threshhold;
}
/** defines whether to use the median of three method of choosing a pivot or not */
void setMedianOfThree( boolean flag ) {
useMedOfThree = flag;
}
/** creates randomized arrays of various sizes */
void makeArrays() {
miniArray = new Double[KID_SIZED];
for( int j = 0; j < miniArray.length; j++ )
miniArray[j] = new Double( Math.ceil( tempValue * Math.random() ) );
smallArray = new Double[SMALL];
for( int j = 0; j < smallArray.length; j++ )
smallArray[j] = new Double( Math.ceil( tempValue * Math.random() ) );
mediumArray = new Double[MEDIUM];
for( int j = 0; j < mediumArray.length; j++ )
mediumArray[j] = new Double( Math.ceil( tempValue * Math.random() ) );
largeArray = new Double[LARGE];
for( int j = 0; j < largeArray.length; j++ )
largeArray[j] = new Double( Math.ceil( tempValue * Math.random() ) );
superArray = new Double[SUPER_SIZED];
for( int j = 0; j < superArray.length; j++ )
superArray[j] = new Double( Math.ceil( tempValue * Math.random() ) );
}
/** launches the sorting program */
public static void main( String[] args ) {
Sort sortQuick = new Sort();
sortQuick.makeArrays();
sortQuick.timedSort();
//System.out.println(sortQuick.miniArray[KID_SIZED-1].toString());
}
}