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

Popular posts from this blog

VB.NET - Membuat Angka Acak

Kenapa dinamai windows?

Konversi Desimal ke Biner Menggunakan Stack - Java