Amir Hamzah

Just learning material sharing …
Subscribe

Archive for March, 2012

Buble-Sort dengan Java

March 28, 2012 By: amir Category: Java, Uncategorized No Comments →


class Urut
{public static void main(String[] arg)
{int[] a={12, 3, 15, 7};
int[] b;
System.out.print(“DATA ASAL : “); cetak(a);
b=Urutkan(a);
System.out.print(“DATA URUT : “);cetak(b);
}
private static void cetak(int []a)
{for (int i=0;i<a.length;i++)
System.out.print(a[i]+” , “);
System.out.println(“”);
}

private static int[] Urutkan(int [] a)
{int d=0;
for (int i=0;i<a.length-1; i++)
for (int j=i+1; j<a.length; j++){d=a[i]; a[i]=a[j]; a[j]=d;} ;
return a;
}
}

HASIL :