Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objective: Comparison of Sorting Algorithms Write a main java program to read in

ID: 3577534 • Letter: O

Question

Objective: Comparison of Sorting Algorithms

Write a main java program to read input file into separate array for Insertion Sort, Merge Sort and Quick Sort. Compare efficiency for each sort Algorism by display the System.nanoTime() for each sort.

Given Code:

//********************************************************************
// SelectionSortS.java   
//
//********************************************************************

import java.util.Comparator;

public class SelectionSortS
{
private SortNode list;
  
//-----------------------------------------------------------------
// Creates an initially empty linked list.
//-----------------------------------------------------------------
public SelectionSortS()
{
list = null;
}

//-----------------------------------------------------------------
// Adds an integer to the linked list
//-----------------------------------------------------------------
public void add(String value)
{
SortNode node = new SortNode(value);
SortNode current = null;

if (list == null)
list = node;
else
{
current = list;
while (current.next != null)
current = current.next;
current.next = node;
}
}
  
//-----------------------------------------------------------------
// Sorts the linked list using the selection sort.
//-----------------------------------------------------------------
public void sort()
{
SortNode current = list;
SortNode min = list;
SortNode swapPos = list;
  
  
if (list == null)
return;

while (swapPos.next != null)
{
while (current.next != null) // find min value
{
current = current.next;
if (current.value.compareTo(min.value) <0)
min = current;
}

// Swap the values
if (min != swapPos) // a swap was found
{
String temp = min.value;
min.value = swapPos.value;
swapPos.value = temp;
}
swapPos = swapPos.next;
current = swapPos;
min = current;
}
}
  
//-----------------------------------------------------------------
// Returns a listing of the contents of the linked list.
//-----------------------------------------------------------------
public String toString()
{
String report = "";
SortNode current = list;
  
if (current != null)
{
report += String.valueOf(current.value) + " ";
while (current.next != null)
{
current = current.next;
report += String.valueOf(current.value) + " ";
}
}

return report;
}
  
//*****************************************************************
// An inner class that represents a node containing String.
// The public variables are only visible in the outer class.
//*****************************************************************
private class SortNode
{
public String value;
public SortNode next;

//--------------------------------------------------------------
// Sets up the node.
//--------------------------------------------------------------
public SortNode (String current)
{
value = current;
next = null;
}
}
}

/** Source code example for "A Practical Introduction to Data
Structures and Algorithm Analysis, 3rd Edition (Java)"
by Clifford A. Shaffer
Copyright 2008-2011 by Clifford A. Shaffer
*/

// Sorting main function for testing correctness of sort algorithm.
// To use: <sortname> [+/-] <size_of_array> <threshold>
// + means increasing values, - means decreasing value and no
// parameter means random values;
// where <size_of_array> controls the number of objects to be sorted;
// and <threshold> controls the threshold parameter for certain sorts, e.g.,
// cutoff point for quicksort sublists.

import java.io.*;

public class QuickSort {

static int THRESHOLD = 0;

static int ARRAYSIZE = 0;

static <E extends Comparable<? super E>> void Sort(E[] A) {
qsort(A, 0, A.length-1);
}

static int MAXSTACKSIZE = 1000;
static <E extends Comparable<? super E>>

void qsort(E[] A, int i, int j) { // Quicksort
int pivotindex = findpivot(A, i, j); // Pick a pivot
DSutil.swap(A, pivotindex, j); // Stick pivot at end
// k will be the first position in the right subarray
int k = partition(A, i-1, j, A[j]);
DSutil.swap(A, k, j); // Put pivot in place
if ((k-i) > 1) qsort(A, i, k-1); // Sort left partition
if ((j-k) > 1) qsort(A, k+1, j); // Sort right partition
}

static <E extends Comparable<? super E>>
int partition(E[] A, int l, int r, E pivot) {
do { // Move bounds inward until they meet
while (A[++l].compareTo(pivot)<0);
while ((r!=0) && (A[--r].compareTo(pivot)>0));
DSutil.swap(A, l, r); // Swap out-of-place values
} while (l < r); // Stop when they cross
DSutil.swap(A, l, r); // Reverse last, wasted swap
return l; // Return first position in right partition
}

static <E extends Comparable<? super E>>
int findpivot(E[] A, int i, int j)
{ return (i+j)/2; }


}

/** Source code example for "A Practical Introduction to Data
Structures and Algorithm Analysis, 3rd Edition (Java)"
by Clifford A. Shaffer
Copyright 2008-2011 by Clifford A. Shaffer
*/

// Sorting main function for testing correctness of sort algorithm.
// To use: <sortname> [+/-] <size_of_array> <threshold>
// + means increasing values, - means decreasing value and no
// parameter means random values;
// where <size_of_array> controls the number of objects to be sorted;
// and <threshold> controls the threshold parameter for certain sorts, e.g.,
// cutoff point for quicksort sublists.

import java.io.*;

public class MergeSort {

static int THRESHOLD = 0;

static int ARRAYSIZE = 0;

@SuppressWarnings("unchecked") // Generic array allocation
static <E extends Comparable<? super E>> void Sort(E[] A) {
E[] temp = (E[])new Comparable[A.length];
mergesort(A, temp, 0, A.length-1);
}

static <E extends Comparable<? super E>>
void mergesort(E[] A, E[] temp, int l, int r) {
int mid = (l+r)/2; // Select midpoint
if (l == r) return; // List has one element
mergesort(A, temp, l, mid); // Mergesort first half
mergesort(A, temp, mid+1, r); // Mergesort second half
for (int i=l; i<=r; i++) // Copy subarray to temp
temp[i] = A[i];
// Do the merge operation back to A
int i1 = l; int i2 = mid + 1;
for (int curr=l; curr<=r; curr++) {
if (i1 == mid+1) // Left sublist exhausted
A[curr] = temp[i2++];
else if (i2 > r) // Right sublist exhausted
A[curr] = temp[i1++];
else if (temp[i1].compareTo(temp[i2])<0) // Get smaller
A[curr] = temp[i1++];
else A[curr] = temp[i2++];
}
}

}

/** Source code example for "A Practical Introduction to Data
Structures and Algorithm Analysis, 3rd Edition (Java)"
by Clifford A. Shaffer
Copyright 2008-2011 by Clifford A. Shaffer
*/

// Sorting main function for testing correctness of sort algorithm.
// To use: <sortname> [+/-] <size_of_array> <threshold>
// + means increasing values, - means decreasing value and no
// parameter means random values;
// where <size_of_array> controls the number of objects to be sorted;
// and <threshold> controls the threshold parameter for certain sorts, e.g.,
// cutoff point for quicksort sublists.

import java.io.*;

public class InsertionSort {

static int THRESHOLD = 0;

static int ARRAYSIZE = 0;
static <E extends Comparable<? super E>>
void Sort(E[] A, int l) {
for (int i=1; i<l; i++) // Insert i'th record
for (int j=i; (j>0) && (A[j].compareTo(A[j-1])<0); j--)
DSutil.swap(A, j, j-1);
}


}

Text File (part):

HO09C1068A,HONDA,FIT,Front bumper license plate,2015,7.00
HO11F1213B,HONDA,ODYSSEY,RT Front bumper molding,2014,7.00
KI17B1042A,KIA,FORTE SDN,LT Front bumper cover retainer,2015,7.00
KI17B1043A,KIA,FORTE KOUP,RT Front bumper cover retainer,2015,7.00
SU04D1042D,SUBARU,FORESTER,LT Rear bumper cover retainer,2015,7.00
SU04D1043D,SUBARU,FORESTER,RT Rear bumper cover retainer,2015,7.00
HO11F1213A,HONDA,ODYSSEY,RT Front bumper molding,2014,8.00
HO11F2598A,HONDA,ODYSSEY,LT Front fog lamp cover,2014,9.00
HO11F2599A,HONDA,ODYSSEY,RT Front fog lamp cover,2014,9.00
HY03G2599A,HYUNDAI,ELANTRA SEDAN,RT Front fog lamp cover,2013,9.00
HY03G2598A,HYUNDAI,ELANTRA SEDAN,LT Front fog lamp cover,2013,9.00
SU04D1042C,SUBARU,FORESTER,LT Rear bumper cover retainer,2015,9.00
SU04D1043C,SUBARU,FORESTER,RT Rear bumper cover retainer,2015,9.00
VW11E2513B,VOLKSWAGEN,GOLF,RT Fog Lamp Ring Bezel,2014,9.00
DG06C1042A,DODGE,AVENGER,LT Front bumper cover support,2010,10.00
SZ10C2599A,SUZUKI,GRAND VITARA,RT Front fog lamp cover,2013,11.00
SZ10C2599B,SUZUKI,GRAND VITARA,RT Front fog lamp cover,2013,11.00
SZ10C2598B,SUZUKI,GRAND VITARA,LT Front fog lamp cover,2013,11.00
SZ10C2598A,SUZUKI,GRAND VITARA,LT Front fog lamp cover,2013,12.00
FT18B1043A,FORD TRUCK,F150 (NEW STYLE),RT Front bumper cover support,2008,13.00
FT18B1042A,FORD TRUCK,F150 (NEW STYLE),LT Front bumper cover support,2008,13.00
FT24B1042A,FORD TRUCK,TRANSIT CONNECT,LT Front bumper cover retainer,2014,13.00
FT24B1043A,FORD TRUCK,TRANSIT CONNECT,RT Front bumper cover retainer,2014,13.00
HY11B3014A,KIA,SPORTAGE,Coolant recovery tank,2013,13.00
VW11E2512B,VOLKSWAGEN,GOLF,LT Fog Lamp Ring Bezel,2014,13.00
HY01E1042D,HYUNDAI,ACCENT SEDAN,LT Rear bumper cover retainer,2015,14.00
HY01E1043D,HYUNDAI,ACCENT SEDAN,RT Rear bumper cover retainer,2015,14.00
CH03B1068A,CHRYSLER,200 SDN,Front bumper license plate,2015,15.00
LR15A1043A,LAND ROVER,RANGE ROVER,RT Rear bumper cover support,2012,15.00
LR15A1042A,LAND ROVER,RANGE ROVER,LT Rear bumper cover support,2012,15.00
MA01E1223B,MAZDA,3 HB,Grille mounting panel,2015,15.00
AC12D1200C,ACURA,MDX,Front bumper grille,2015,16.00
DG06C1043A,DODGE,AVENGER,RT Front bumper cover support,2010,16.00
HO03N2513D,HONDA,CIVIC CPE,RT Front fog lamp bezel,2015,16.00
HO03N2512D,HONDA,CIVIC CPE,LT Front fog lamp bezel,2015,16.00
HY07F3014A,KIA,SORENTO,Coolant recovery tank Assy,2015,16.00
MA05B1297A,MAZDA,5,RT Hood hinge assy,2015,16.00
MA05B1296A,MAZDA,5,LT Hood hinge assy,2015,16.00
MI15C1043A,MITSUBISHI,OUTLANDER,RT Front bumper cover retainer,2015,16.00
MI15C1042A,MITSUBISHI,OUTLANDER,LT Front bumper cover retainer,2015,16.00
TO27D1042B,TOYOTA,RAV4,Front bumper cover retainer,2012,16.00
CH03B1068B,CHRYSLER,200 SDN,Rear bumper license bracket,2015,17.00
JP08A1068A,JEEP,PATRIOT,Front bumper license plate,2015,17.00
KI05C1288A,KIA,RIO5,Windshield washer tank assy,2011,17.00
MA01A1043B,MAZDA,3,RT Front bumper bracket,2009,17.00
MA01A1042B,MAZDA,3,LT Front bumper bracket,2009,17.00
AC14B1288A,ACURA,RDX,Windshield washer tank assy,2015,18.00
CH03B2598A,CHRYSLER,200 SDN,LT Front fog lamp cover,2015,18.00
CH03B2599A,CHRYSLER,200 SDN,RT Front fog lamp cover,2015,18.00
HO11F1212A,HONDA,ODYSSEY,LT Front bumper molding,2014,18.00
HY01E1042C,HYUNDAI,ACCENT HB,LT=RT Front bumper cover support,2015,18.00
HY01E1068A,HYUNDAI,ACCENT HB,Front bumper license plate,2015,18.00
SU07B1011A,SUBARU,LEGACY,Front bumper cover support,2015,18.00
SU07A2599B,SUBARU,LEGACY,RT Front fog lamp cover,2014,18.00
SU07A2598B,SUBARU,LEGACY,LT Front fog lamp cover,2014,18.00
CV15F1297A,CHEVROLET,IMPALA,RT Hood hinge,2015,19.00
HO07F2830A,HONDA,CR-V,LT Rear bumper reflector,2015,19.00
HO07F2831A,HONDA,CR-V,RT Rear bumper reflector,2015,19.00
MA01D1068A,MAZDA,3 SDN,Front bumper license plate,2013,19.00
NI28A2598B,NISSAN,ROGUE/ROGUE SELECT,LT=RT Front fog lamp cover,2014,19.00
VW14F1068A,VOLKSWAGEN,PASSAT,Front bumper license plate,2015,19.00
CV15F1296A,CHEVROLET,IMPALA,LT Hood hinge,2015,20.00
KI04D1213A,KIA,OPTIMA,RT Front bumper molding,2015,20.00
NI19C2598A,NISSAN,FRONTIER PICKUP,LT=RT Front fog lamp cover,2015,20.00
SZ08A1042B,SUZUKI,SX4,LT Rear bumper cover support,2013,20.00
SZ08A1043B,SUZUKI,SX4,RT Rear bumper cover support,2013,20.00
CT06B1068A,CHEVROLET TRUCK,EQUINOX,Front bumper license plate,2015,22.00
KI04D1212A,KIA,OPTIMA,LT Front bumper molding,2015,23.00
MB04B2599A,MERCEDES BENZ,E-CLASS SEDAN,RT Front bumper grille,2006,23.00
MB04B2598A,MERCEDES BENZ,E-CLASS SEDAN,LT Front bumper grille,2006,23.00
FO03D1057B,FORD,CROWN VICTORIA,Front bumper impact strip,2002,24.00
HO11F1212B,HONDA,ODYSSEY,LT Front bumper molding,2014,24.00
VO19A2598A,VOLVO,XC60,LT Front fog lamp cover,2013,24.00
VO19A2599A,VOLVO,XC60,RT Front fog lamp cover,2013,24.00
CH25F2598A,CHRYSLER,TOWN & COUNTRY VAN,LT Front fog lamp cover,2015,25.00
CT08A1250B,CHEVROLET TRUCK,HHR,LT Front fender splash shield,2011,25.00
CT08A1251B,CHEVROLET TRUCK,HHR,RT Front fender splash shield,2008,25.00
FO03E1251B,FORD,CROWN VICTORIA,RT Front fender splash shield,2011,25.00
FO12C2830AQ,FORD,FUSION,LT Rear bumper reflector,2015,25.00
FO12C2831AQ,FORD,FUSION HYBRID,RT Rear bumper reflector,2015,25.00
HO09C1296A,HONDA,FIT,LT Hood hinge,2015,25.00
HO09C1297A,HONDA,FIT,RT Hood hinge,2015,25.00
JP02C1068A,JEEP,CHEROKEE,Front bumper license plate,2015,25.00
MI10B1223A,MITSUBISHI,LANCER,Front panel molding,2015,25.00
TO03L1066A,TOYOTA,CAMRY,LT Front fender bracket,2015,25.00
TO03L1067A,TOYOTA,CAMRY,RT Front fender bracket,2015,25.00
TO16D1296A,TOYOTA,HIGHLANDER HYBRID,LT Hood hinge,2015,25.00
TO16D1297A,TOYOTA,HIGHLANDER,RT Hood hinge,2015,25.00
TO27D2599C,TOYOTA,RAV4,RT Front fog lamp cover,2012,25.00
TO27D2598C,TOYOTA,RAV4,LT Front fog lamp cover,2012,25.00
CH25F2599A,CHRYSLER,TOWN & COUNTRY VAN,RT Front fog lamp cover,2015,26.00
FO08A2831A,FORD,FIESTA HB,RT Rear bumper reflector,2015,26.00
MA35A1288A,MAZDA,2,Windshield washer tank,2014,26.00
CH03B2598C,CHRYSLER,200 SDN,LT Front fog lamp cover,2015,27.00
CH03B2599C,CHRYSLER,200 SDN,RT Front fog lamp cover,2015,27.00
FO03E1250B,FORD,CROWN VICTORIA,LT Front fender splash shield,2011,27.00
HU03A1915A,HUMMER,H3T,Rear gate handle bezel,2010,27.00
JP01F1067B,JEEP,CHEROKEE,RT Radiator support bracket,2015,27.00
JP01F1066B,JEEP,CHEROKEE,LT Radiator support bracket,2015,27.00
SZ10C1223A,SUZUKI,GRAND VITARA,Grille mounting panel,2013,27.00
HO07D2830AQ,HONDA,CR-V,LT Rear reflector,2009,28.00
LX06C2599A,LEXUS,GS450h,RT Front fog lamp cover,2015,28.00
MA11A1250D,MAZDA,CX-9,LT Front fender splash shield,2015,28.00
MA11A1251D,MAZDA,CX-9,RT Front fender splash shield,2015,28.00
NI37A1352B,NISSAN,CUBE,LT Front=Rear door handle inside,2014,28.00
NI37A1353B,NISSAN,CUBE,RT Front=Rear door handle inside,2014,28.00
TO03L1042B,TOYOTA,CAMRY HYBRID,LT Front bumper cover retainer,2015,28.00
TO03L1043B,TOYOTA,CAMRY HYBRID,RT Front bumper cover retainer,2015,28.00
BM44B1068A,BMW,X3,Front bumper license plate,2014,29.00
MI15B1087A,MITSUBISHI,RVR,Front bumper cover filler,2015,29.00
SC06A1297A,SCION,FR-S,RT Hood hinge assy,2015,29.00
SC06A1296A,SCION,FR-S,LT Hood hinge assy,2015,29.00
TO03L1296A,TOYOTA,CAMRY,LT Hood hinge,2015,29.00
TO03L1297A,TOYOTA,CAMRY HYBRID,RT Hood hinge,2015,29.00
TO07D1066B,TOYOTA,COROLLA,LT Rear bumper bracket,2015,29.00
TO07D1067B,TOYOTA,COROLLA,RT Rear bumper bracket,2015,29.00
HO03L1223A,HONDA,CIVIC CPE,LT Grille bracket,2011,30.00
HO03L1223B,HONDA,CIVIC CPE,RT Grille bracket,2011,30.00
HO13C1228B,HONDA,PILOT,Lower engine cover,2015,30.00
HY02B3014B,HYUNDAI,SONATA HYBRID,Coolant recovery tank,2015,30.00
BM12D2598B,BMW,5 SERIES,LT Front bumper grille,2010,31.00
BM12D2599B,BMW,5 SERIES,RT Front bumper grille,2010,31.00
FO08A2830A,FORD,FIESTA HB,LT Rear bumper reflector,2015,31.00
FO03D1057A,FORD,CROWN VICTORIA,Front bumper impact strip,2002,31.00
LX06C2830AQ,LEXUS,GS350,LT Rear bumper reflector,2015,31.00
LX06C2831AQ,LEXUS,GS350,RT Rear bumper reflector,2015,31.00
DT04E1200C,DODGE TRUCK,DURANGO,Front bumper grille,2014,32.00
HO07D1011A,HONDA,CR-V,Front bumper cover support,2011,32.00
LX06C2598A,LEXUS,GS450h,LT Front fog lamp cover,2015,32.00
NI29I3014A,NISSAN,SENTRA,Coolant recovery tank,2014,32.00
CT24A2598B,CHEVROLET TRUCK,TRAILBLAZER,LT Fog lamp cover,2009,33.00
CV01B3014A,CHEVROLET,AVEO SDN,Coolant recovery tank,2011,33.00
HO17A1228A,HONDA,ACCORD CROSSTOUR,Lower engine cover,2015,33.00
TO38A1088C,TOYOTA,YARIS HB,LT Rear bumper filler,2011,33.00
TO35D1200A,TOYOTA,TUNDRA PICKUP,Front bumper grille,2015,33.00
TO38A1088B,TOYOTA,YARIS HB,LT Rear bumper filler,2008,33.00
TO38A1089B,TOYOTA,YARIS HB,RT Rear bumper filler,2008,33.00
TO38A1089C,TOYOTA,YARIS HB,RT Rear bumper filler,2011,33.00
AC14B1288B,ACURA,RDX,Windshield washer tank assy,2015,34.00
CT24A2599B,CHEVROLET TRUCK,TRAILBLAZER,RT Fog lamp cover,2009,34.00
NI27E1296A,NISSAN,QUEST VAN,LT Hood hinge,2015,34.00
NI27E1297A,NISSAN,QUEST VAN,RT Hood hinge,2015,34.00
VW11E2512A,VOLKSWAGEN,GOLF,LT Fog Lamp Ring Bezel,2014,34.00
VW11E2513A,VOLKSWAGEN,GOLF,RT Fog Lamp Ring Bezel,2014,34.00
MA06C1251A,MAZDA,6,RT Front fender liner,2015,35.00
MA06C1250A,MAZDA,6,LT Front fender liner,2015,35.00
TO35D1200AQ,TOYOTA,TUNDRA PICKUP,Front bumper grille,2015,35.00
AC12D1200B,ACURA,MDX,Front bumper grille,2015,36.00
CV15F1042C,CHEVROLET,IMPALA,Rear bumper cover support,2015,36.00
FO23F1296B,FORD,TAURUS,LT Hood hinge,2015,36.00
FO23F1297B,FORD,TAURUS,RT Hood hinge,2015,36.00
JP05B2830AQ,DODGE,JOURNEY,LT Rear bumper reflector,2015,36.00
JP05B2831AQ,DODGE,JOURNEY,RT Rear bumper reflector,2015,36.00
JP08A2592AQ,JEEP,PATRIOT,LT=RT Fog lamp lens/housing,2015,36.00
MA35A3014A,MAZDA,2,Coolant recovery tank Assy,2014,36.00
NI37A1068A,NISSAN,CUBE,Front bumper license plate,2014,36.00
FO19H1068A,FORD,MUSTANG,Front bumper license plate,2015,37.00
GT13D1090A,GMC TRUCK,SIERRA 2500/3500,Front bumper air shield lower,2015,37.00
JP01F1088B,JEEP,GRAND CHEROKEE,LT Front bumper filler,2015,37.00
JP01F1089B,JEEP,GRAND CHEROKEE,RT Front bumper filler,2015,37.00
AC24A1200A,ACURA,ILX HYBRID,Grille,2014,38.00
CT15F1066A,GMC TRUCK,SIERRA 2500/3500,LT Front bumper support bracket,2015,38.00
CT15F1067A,GMC TRUCK,SIERRA 2500/3500,RT Front bumper support bracket,2015,38.00
MA06C1200BQ,MAZDA,6,Grille,2015,38.00
MA09A1234A,MAZDA,CX-5,Hood latch,2015,38.00
SZ10C1200B,SUZUKI,GRAND VITARA,Front bumper grille,2013,38.00
CD13D3014A,GMC TRUCK,YUKON,Coolant recovery tank,2015,39.00
CT16D1090A,CHEVROLET TRUCK,SILVERADO 2500/3500,Front bumper air shield lower,2015,39.00
HO11F1054A,HONDA,ODYSSEY,Front bumper molding,2014,39.00
MA01E1213A,MAZDA,3 HB,RT Grille molding lower,2015,39.00
MA01E1212A,MAZDA,3 HB,LT Grille molding lower,2015,39.00
LR15A1067A,LAND ROVER,RANGE ROVER,,2012,40.00
LR15A1066A,LAND ROVER,RANGE ROVER,,2012,40.00
NI14D1068B,NISSAN,ALTIMA SDN,Front bumper license plate,2012,40.00
CD13D3014B,GMC TRUCK,YUKON XL,Coolant recovery tank,2015,41.00
DT06E1296C,DODGE TRUCK,PICKUP RAM R1500,LT Hood hinge assy,2015,41.00
GT01A2599A,GMC TRUCK,ACADIA,RT Front fog lamp cover,2015,41.00
GT01A2598A,GMC TRUCK,ACADIA,LT Front fog lamp cover,2015,41.00
MA01D1288A,MAZDA,5,Windshield washer tank assy,2014,41.00
MA06C1234A,MAZDA,6,Hood latch,2015,41.00
TO27E2830AQ,TOYOTA,RAV4,LT Rear bumper reflector,2015,41.00
TO27E2831AQ,TOYOTA,RAV4,RT Rear bumper reflector,2015,41.00
DT06D1296C,DODGE TRUCK,PICKUP R1500 EX MEGA CAB,LT Hood hinge,2009,42.00
DT06D1297C,DODGE TRUCK,PICKUP R1500 EX MEGA CAB,RT Hood hinge,2009,42.00
DT06E1297C,DODGE TRUCK,PICKUP RAM R1500,RT Hood hinge assy,2015,42.00
HO09C2598A,HONDA,FIT,LT Front fog lamp cover,2015,42.00
HO09C2599A,HONDA,FIT,RT Front fog lamp cover,2015,42.00
MA01E1213AQ,MAZDA,3 SDN,RT Grille molding lower,2015,42.00
MA01E1212AQ,MAZDA,3 HB,LT Grille molding lower,2015,42.00
NI28B1068A,NISSAN,ROGUE,Front bumper license plate,2015,42.00
SU07A2598A,SUBARU,LEGACY,LT Front fog lamp cover,2014,42.00
SU07A2599A,SUBARU,LEGACY,RT Front fog lamp cover,2014,42.00
JP01G1220B,JEEP,CHEROKEE,RT Headlamp mounting panel,2015,43.00
KI05C1200G,KIA,RIO,Front bumper grille,2011,43.00
VW02C2598A,VOLKSWAGEN,BEETLE CONV,LT Front fog lamp cover,2015,43.00
VW11E1068A,VOLKSWAGEN,GOLF,Rear bumper license bracket,2014,43.00
HY03G1250C,HYUNDAI,ELANTRA COUPE,LT Front fender liner,2014,44.00
JP01G1220A,JEEP,CHEROKEE,LT Headlamp mounting panel,2015,44.00
BM05A2508A,BMW,1 SERIES,LT Headlamp bracket,2013,45.00
BM05A2509A,BMW,1 SERIES,RT Headlamp bracket,2013,45.00
CT06B1288B,CHEVROLET TRUCK,EQUINOX,Windshield washer tank assy,2013,45.00
HO07E1288A,HONDA,CR-V,Windshield washer tank,2012,45.00
HO07E1288C,HONDA,CR-V,Windshield washer tank,2014,45.00
KI17B1200B,KIA,FORTE5,Front bumper grille,2015,45.00
MA27C2540AQ,MAZDA,PROTG,LT Corner lamp,2000,45.00
NI14E1250B,NISSAN,ALTIMA SDN,LT Front fender liner,2015,45.00
SU05D1250C,SUBARU,IMPREZA,LT Front fender liner,2014,45.00
SU05D1251C,SUBARU,IMPREZA,RT Front fender liner,2014,45.00
BM06E2520BQ,BMW,3 SERIES SDN/HB/WGN,LT Parklamp,2003,46.00
BM06E2521BQ,BMW,3 SERIES SDN/HB/WGN,RT Parklamp,2003,46.00
FT18C1042D,FORD TRUCK,F150 SVT RAPTOR,LT Front bumper cover support,2014,46.00
HO03K1223A,HONDA,CIVIC CPE,Front panel molding,2011,46.00
HO03M1288A,HONDA,CIVIC HYBRID,Windshield washer tank,2012,46.00
HY09E1288A,HYUNDAI,SONATA,Windshield washer tank,2010,46.00
HY09C1288A,KIA,OPTIMA,Windshield washer tank,2006,46.00
TO03L2530B,TOYOTA,CAMRY,LT Front signal lamp,2015,46.00
TO03L2531B,TOYOTA,CAMRY,RT Front signal lamp,2015,46.00
CT24A1191A,GMC TRUCK,ENVOY,Rear bumper step pad,2009,47.00
FT18C1043D,FORD TRUCK,F150 SVT RAPTOR,RT Front bumper cover support,2014,47.00
HO16A1288A,HONDA,INSIGHT,Windshield washer tank,2011,47.00
IN04A2800C,INFINITI,G35 SEDAN,LT Taillamp assy inner,2006,48.00
IN04A2801C,INFINITI,G35 SEDAN,RT Taillamp assy inner,2006,48.00
MA01E1223A,MAZDA,3 HB,Grille bracket,2015,48.00

Explanation / Answer

Answer:

Insertion Sort :

public class MyInsertionSort {

    public static void main(String[] args) {

         

        int[] input = { 4, 2, 9, 6, 23, 12, 34, 0, 1 };

        insertionSort(input);

    }

     

    private static void printNumbers(int[] input) {

         

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

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

        }

        System.out.println(" ");

    }

    public static void insertionSort(int array[]) {

        int n = array.length;

        for (int j = 1; j < n; j++) {

            int key = array[j];

            int i = j-1;

            while ( (i > -1) && ( array [i] > key ) ) {

                array [i+1] = array [i];

                i--;

            }

            array[i+1] = key;

            printNumbers(array);

        }

    }

}

Merge Sort :

QuickSort:

public class MyQuickSort {

     

    private int array[];

    private int length;

    public void sort(int[] inputArr) {

         

        if (inputArr == null || inputArr.length == 0) {

            return;

        }

        this.array = inputArr;

        length = inputArr.length;

        quickSort(0, length - 1);

    }

    private void quickSort(int lowerIndex, int higherIndex) {

         

        int i = lowerIndex;

        int j = higherIndex;

       

        int pivot = array[lowerIndex+(higherIndex-lowerIndex)/2];

       

        while (i <= j) {

           

            while (array[i] < pivot) {

                i++;

            }

            while (array[j] > pivot) {

                j--;

            }

            if (i <= j) {

                exchangeNumbers(i, j);

              

                i++;

                j--;

            }

        }

       

        if (lowerIndex < j)

            quickSort(lowerIndex, j);

        if (i < higherIndex)

            quickSort(i, higherIndex);

    }

    private void exchangeNumbers(int i, int j) {

        int temp = array[i];

        array[i] = array[j];

        array[j] = temp;

    }

     

    public static void main(String a[]){

         

        MyQuickSort sorter = new MyQuickSort();

        int[] input = {24,2,45,20,56,75,2,56,99,53,12};

        sorter.sort(input);

        for(int i:input){

            System.out.print(i);

            System.out.print(" ");

        }

    }

}