Insertion Sort d Java

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

package insertionsort;

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

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int[] array={4,6,3,8,2,5,8,9,6};

for(int j=1;j<array.length;j++){
int sementara=array[j];
int i=j-1;
while(i>=0 && array[i]>sementara){
array[i+1]=array[i];
i–;
}
array[i+1]=sementara;
}

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