Selection Sort

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

package selectionsort;

/**
*
* @author Angga
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int[] array={-5,-8,-11,0,34,1,1,6,9,22,15};

int idxMin;
int tmp;
for(int j=0;j<array.length-1;j++){
idxMin=j;
for(int i=j+1;i<array.length;i++){
if(array[i]<array[idxMin])
idxMin=i;
}
if(idxMin!=j){
tmp=array[idxMin];
array[idxMin]=array[j];
array[j]=tmp;
}

}
for(int i=0;i<array.length;i++){
System.out.print(array[i]+” “);
}

}

}

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