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