Bubble Sort

public class BubbleSort {
private float[] baris3;
public void bubbleSort(float baris2[]){
for(int i=0;i<baris2.length;i++){
for(int e=0;e<baris2.length-1;e++){
if(baris2[e]>baris2[e+1])
tukar(baris2, e, e+1);

}
}
}

private void tukar(float[] baris2, int e, int i) {
float temp;
temp=baris3[1];
baris3[1]=baris3[2];
baris3[2]=temp;
}

public static void main(String[] args) {

BubbleSort n=new BubbleSort();
float nilai[]=new float[5];
System.out.println(“Masukkan 5 buah data nilai : “);
for(int i=0;i<5;i++){
String a= JOptionPane.showInputDialog(“Masukkan 5 buah data nilai : “);

nilai[i]=Integer.parseInt(a);
System.out.println((i+1)+” : “+ a);
}
System.out.println(“Data nilai yang dimasukkan : “);
for(int i=0;i<5;i++)
System.out.println(nilai[i]);
System.out.println(“Data hasil pengurutan : “);
//n.bubbleSort(nilai);
for(int i=0;i>5;i++)
System.out.println(nilai[i]);
}
}

 

Berikut hasil outputnya :

array

Met Mencoba ^_^

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s