class SelectionSort
{
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-1;i++)
{
int pos=i;
for(int j=i+1;j<A.length;j++)
{
if(A[j]<A[pos])
{
pos=j;
}
}
if(pos!=i)
{
int tampung=A[pos];
A[pos]=A[i];
A[i]=tampung;
}
}
System.out.println("\nAfter Sorting : ");
for(int i=0;i<A.length;i++)
{
System.out.print(" "+A[i]);
}
System.out.println();
}
}//use "SelectionSort.java" for file name
Capture :
Ads 970x90
Sabtu, 03 Maret 2012
SelectionSort ( Java )
Editor
Aguez stw
Published
3/03/2012 01:35:00 PM
Related Posts
Load comments
Langganan:
Posting Komentar (Atom)