class InsertionSort
{
public static int i,j,tampung;
public static void main(String[] args)
{
int A[]={3,4,1,2,8};
System.out.println("Before Sorting :");
for(int i=0;i<A.length;i++)
{
System.out.print(" "+A[i]);
}
for(int i=0;i<A.length;i++)
{
j=i;
tampung=A[i];
while(j>0 && A[j-1] > tampung)
{
A[j]=A[j-1];
j--;
}
A[j]=tampung;
}
System.out.println("\nAfter Sorting : ");
for(int i=0;i<A.length;i++)
{
System.out.print(" "+A[i]);
}
System.out.println();
}
}//use "InsertionSort .java" for file name
Ads 970x90
Sabtu, 03 Maret 2012
InsertionSort ( Java )
Editor
Aguez stw
Published
3/03/2012 01:09:00 PM
Related Posts
Load comments
Langganan:
Posting Komentar (Atom)