class
BubbleSort
{
public static void main(String[] args)
{
int [] array = new int []{ 3 , 5 , 2 , 8 , 4 , 9 , - 1 , 7 };
for ( int num : array)
System.out.println(num);
long timeStart = System.currentTimeMillis();
for ( int i = 0 ; i < 10000000 ; i ++ )
BubbleSort.bubbleSort(array);
long timeEnd = System.currentTimeMillis();
System.out.println( " time: " + (timeEnd - timeStart));
for ( int num : array)
System.out.println(num);
}
static void bubbleSort( int [] array){
int temp;
int i,j;
for (i = 1 ; i < array.length; i ++ ){
for (j = 0 ; j < array.length - i; j ++ ){
if ( array[j] > array[j + 1 ] ){
temp = array[j];
array[j] = array[j + 1 ];
array[j + 1 ] = temp;
}
}
}
}
}
{
public static void main(String[] args)
{
int [] array = new int []{ 3 , 5 , 2 , 8 , 4 , 9 , - 1 , 7 };
for ( int num : array)
System.out.println(num);
long timeStart = System.currentTimeMillis();
for ( int i = 0 ; i < 10000000 ; i ++ )
BubbleSort.bubbleSort(array);
long timeEnd = System.currentTimeMillis();
System.out.println( " time: " + (timeEnd - timeStart));
for ( int num : array)
System.out.println(num);
}
static void bubbleSort( int [] array){
int temp;
int i,j;
for (i = 1 ; i < array.length; i ++ ){
for (j = 0 ; j < array.length - i; j ++ ){
if ( array[j] > array[j + 1 ] ){
temp = array[j];
array[j] = array[j + 1 ];
array[j + 1 ] = temp;
}
}
}
}
}