==============================================
public class InsertionSort{
public static void main(String[] args){
int[] angka = {7,5,3,10,6,8,1};
int i, j, temp;
System.out.println("Sebelum diurutkan :");
for(i=0;i < angka.length;i++)
System.out.print(angka[i]+" ");
System.out.println("\nProses pengurutan :");
for(i=1; i < angka.length; i++){
temp = angka[i];
j = i-1;
while(j > =0 && temp < angka[j]){
angka[j+1] = angka[j];
j = j-1;
}
angka[j+1] = temp;
for(int k=0;k < angka.length;k++)
System.out.print(angka[k]+"\t");
System.out.println();
}
System.out.println("Setelah diurutkan :");
for(i=0;i < angka.length;i++)
System.out.print(angka[i]+" ");
}
}
====================================================
Jangan lupa simpan file dengan nama InsertionSort.java lalu compile dan run.
Semoga berhasil dan sedikit membantu.
1 comments:
salah lagi di line 23 om..cek dulu sebelum di posting
Post a Comment