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