Java - Coding Insertion Sort
/*
* To change this
template, choose Tools | Templates
* and open the
template in the editor.
*/
package tgsinsrtsort;
/**
*
* @author Moch. Afif
*/
public class Tgsinsrtsort {
/**
* @param args the
command line arguments
*/
public static void
main(String[] args) {
// TODO code
application logic here
int
A[]={89,56,78,32,22,434,78};
int
b=A.length;
int i,j,k,l;
int tmp;
System.out.print("Sebelum
Insertion Sort : ");
for(i=0;i<b;i++){
System.out.print(A[i]+" ");
}
System.out.println("\n");
for
(j=1;j<b;j++){
k=A[j];
i=j-1;
while
((i>-1)&&(A[i]>k)){
A[i+1]=A[i];
i--;
}
System.out.print("Proses :");
A[i+1]=k;
for
(i=0;i<b;i++){
System.out.print(A[i]+", ");
}
System.out.print("\n");
}
System.out.print("\nSortir Dengan Insertion Sorting :");
for(i=0;
i<b; i++){
System.out.print(A[i]+" ");
}
System.out.println("\n");
}
}
Untuk Pertanyaan dan Kritik Contact Us
Comments
Post a Comment