Bubble Sort
Bubble Sort adalah metode pencarian yang mengambil dari sifat gelembung yaitu mengampung, artinya mengambil nilai paling besar dan di letakan dipaling kanan. Dibawah ini contoh source codenya:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package verlyproject_sorting;
import java.util.InputMismatchException;
import java.util.Scanner;
/**
*
* @author UltravioletDeveloper
*/
public class VerlyProject_Sorting {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int[] angka = {6,8,1,4,2,7};
int i,j,k,temp;
System.out.println("Sebelum diurutkan :");
for(i=0;i < angka.length;i++){
System.out.print(angka[i]+" ");
}
System.out.println("\n");
for(i=1; i < angka.length-1;i++){
System.out.println("Iterasi "+ i);
for(j=angka.length-1;j >=i; j--){
if(angka[j] < angka[j-1]){
temp = angka[j];
angka[j] = angka[j-1];
angka[j-1] = temp;
}
for(k=0;k < angka.length; k++){
System.out.print(angka[k]+"\t");
}
System.out.println();
}
}
System.out.println("Setelah diurutkan :");
for(i=0; i < angka.length;i++)
System.out.print(angka[i]+" ");
}
}
Tags: Contoh program sorting pada java, Pengertian Bubble sort, Script Sorting pada Java.
Bubble Sort adalah metode pencarian yang mengambil dari sifat gelembung yaitu mengampung, artinya mengambil nilai paling besar dan di letakan dipaling kanan. Dibawah ini contoh source codenya:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package verlyproject_sorting;
import java.util.InputMismatchException;
import java.util.Scanner;
/**
*
* @author UltravioletDeveloper
*/
public class VerlyProject_Sorting {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int[] angka = {6,8,1,4,2,7};
int i,j,k,temp;
System.out.println("Sebelum diurutkan :");
for(i=0;i < angka.length;i++){
System.out.print(angka[i]+" ");
}
System.out.println("\n");
for(i=1; i < angka.length-1;i++){
System.out.println("Iterasi "+ i);
for(j=angka.length-1;j >=i; j--){
if(angka[j] < angka[j-1]){
temp = angka[j];
angka[j] = angka[j-1];
angka[j-1] = temp;
}
for(k=0;k < angka.length; k++){
System.out.print(angka[k]+"\t");
}
System.out.println();
}
}
System.out.println("Setelah diurutkan :");
for(i=0; i < angka.length;i++)
System.out.print(angka[i]+" ");
}
}
Tags: Contoh program sorting pada java, Pengertian Bubble sort, Script Sorting pada Java.

