Thursday, September 14, 2017

CI Jenkins JavaProject1



"A good threat is worth a thousand tests" - Boris Beizer

Saturday, June 10, 2017

Array Sort in Java (better performance)

package yourpackagename;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Timer;

public class ArrayPractices {

public static void main(String[] args){
//Array Declaration
int[] intArray={0, 100, 2, 22, 66, 501, 6, 8, 0};
long startTime= -1;
long endTime = -1;

// Java inbuilt Arrays.sort method from DualPivotQuicksort class method (Arrays.sort)
startTime=System.nanoTime();
Arrays.sort(intArray);

for(int i=0; i<=intArray.length-1;i++){
System.out.println(intArray[i]);
}
endTime= System.nanoTime();
System.out.println("Total execution time: " + (endTime - startTime) );

// User Defined method for sorting Array in ascending order
startTime=System.nanoTime();
int[] op = sorting(intArray, 0, intArray.length-1);
for(int i=0; i<=op.length-1; i++){
System.out.println(op[i]);
}

endTime= System.nanoTime();
System.out.println("Total execution time: " + (endTime - startTime) );
}

public static int[] sorting(int[] a, int start, int end){
int lowVal=-1;
int highVal=-1;
for(int i=start; i<=end; i++){
if(a.length-1>=i+1){
if(a[i]>a[i+1]){
lowVal = a[i+1];
highVal = a[i];
a[i]=lowVal;
a[i+1]=highVal;
i--;
}else if(a[i]<a[i+1]){
for(int k=end; k>=i+1; k--){
if(a.length-1>=k){
if(a[k]<a[i]){
highVal = a[i];
lowVal = a[k];
a[k]=highVal;
a[i]=lowVal;
}

}
}
}
}
}
return a;
}
}

There was an error in this gadget