Java - Coding Buble Sort
/*
* To change this
template, choose Tools | Templates
* and open the
template in the editor.
*/
package tgsbbsort;
/**
*
* @author Moch. Afif
*/
public class Tgsbbsort {
/**
* @param args the
command line arguments
*/
public static void
main(String[] args) {
// TODO code
application logic here
int A[] =
{34,65,43,56,87,98,76};
int
b=A.length;
int i,j,k,l;
int tmp;
System.out.print("Sebelum Bubble Sort : ");
for(i=0;i<b;i++){
System.out.print(A[i]+" ");
}
System.out.print("\n");
for (i=0;
i<=b-1; i++){
for (j=0;
j<=b-i-2; j++){
if
(A[j] > A [j + 1]){
tmp=(A [j]);
A[j]=A[j + 1];
A
[j + 1]= tmp;
}
System.out.println();
System.out.print("Proses: ");
for(k=0;
k<b; k++){
System.out.print(A[k]+" ");
}
}
}
System.out.println();
System.out.print("\nSortir Dengan Bubble Sorting :");
for(i=0;
i<b; i++){
System.out.print(A[i]+" ");
}
System.out.println("\n");
}
}
Untuk Pertanyaan dan Kritik Contact Us
Comments
Post a Comment