Selection Sort di Java

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author HP
*/
public class SelectionSort {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int[] data={-5,-8,-11,0,34,1,1,6,9,22,15};
int i,j,tampung,pos;
System.out.println(” Sorting (SELECTION) Oleh :”);
System.out.println(” NAMA : ANGGA ARI WIJAYA”);
System.out.println(” N.I.M : 102410101070″+”\n”);
System.out.println(” Data Sebelum sorting “);
for(i=0;i<data.length;i++){
System.out.print(data[i]+" ");
}
System.out.println("");
for(i=0;i<data.length-1;i++){
pos=i;
for(j=i+1;j<data.length;j++){
if(data[j]<data[pos]){
pos=j;
}
}
if(pos!=i){
tampung=data[pos];
data[pos]=data[i];
data[i]=tampung;
}
}
System.out.println(" Data Setelah sorting");
for(i=0;i<data.length;i++){
System.out.print(data[i]+" ");
}
System.out.println("");
}
}

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 )

Foto Google

You are commenting using your Google 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 )

Connecting to %s