CODING INSERTION SORT DENGAN BAHASA JAVA
![](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw4mqLk0_ZWhpIawtpZFE7CKXU8Dtfv1Ey7AQSpRlcDPrvEdlGT_4KmYF36GuUtfoeSLl46ucNaX6hAbTP1NvyX6kYXvwdfu_2GRRD8k91TpA30v6FKcfLn4YFU6r4FomLDp7G9N8qu4BI/s0/CODING.jpg)
package insertion.sort;
/**
*
*
@author UI PC
*/
public class InsertionSort {
/**
*
@param args the command line arguments
*/
public static void main(String[] args) {
int angka []= {23, 46, 12, 25, 57, 34};
int key, index = 0;
//insertion sort
for (int i = 0; i < angka.length; i++) {
key = angka[i];
index = i;
for (int j = (i - 1); j >= 0; j--) {
if (key < angka[j]){
angka[j+1] = angka[j];
index = j;
}
}
angka[index] = key;
}
//end insertion sort
//output sort
for (int i = 0; i < angka.length; i++) {
System.out.print(angka[i] + "\t");
}
System.out.println("");
}
}
Apabila coding di atas di run, maka outputnya seperti berikut :