RSS

selection sort di java (sortselect.java)

24 Des

source code:

public class sortselect {
public static void main(String[] args) {
int data[] = {5,9,3,1,2,-1,90,8,5,10};
int min;
System.out.println(“Sebelum diurutkan :”);
for(int i=0;i<10;i++){
System.out.print(” “+ data[i]);
}

System.out.println(“\n”);
System.out.println(“PROGRESS:”);
for(int i=0;i<9;i++){
min = i;
//MENENTUKAN BIL. TERKECIL
for(int j=i+1;j<10;j++){
if(data[j] < data[min]){
min = j;
}
}
//BILANGAN TERKECIL DI TUKAR TEMPAT SESUAI URUTAN
int temp = data[min];
System.out.println(“Saat i=”+i+” , Bilangan terkecilnya = “+data[min]+
” di data ke[“+min+”]”);
data[min] = data[i];
data[i] = temp;

}
System.out.println (“\nAscending :”);
for(int i=0;i<10;i++){
System.out.print(” “+ data[i]);
}
System.out.println(“\n\nBilangan paling kecil dari semua bilangan = “+data[0]+”\n\n”);
}
}

running program

 
Tinggalkan komentar

Ditulis oleh pada 24 Desember 2011 in java programming, sorting

 

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

 
%d blogger menyukai ini: