Selection Sort in Jeliot

import jeliot.io.*;

public class Sorting {
    public static void main() {
       
int []a = new int [20];
int cur,x,temp,cur2,temp2;

System.out.print("Banyak Data : ");
x=Input.readInt();
    for(int i=0;i<x;i++){
    System.out.print("Data [");
    System.out.print(i+1);
    System.out.print("] : ");
    a[i]=Input.readInt();
    }
    for(int i=0;i<x;i++){
    cur=i;
    cur2=x;
    for(int k=i+1;k<x;k++){
            if(a[cur]>a[k]){
            cur=k;
            }
    }
    for(int t=x;t<x;t--){
            if(a[cur2]<a[t]){
            cur2=t;
            }
    
    temp2=a[t];
    a[t]=a[cur2];
    a[cur2]=temp2;
    }
    
    temp=a[i];
    a[i]=a[cur];
    a[cur]=temp;
    }
    for(int i=0;i<x;i++){
    System.out.print(" ");
    System.out.print(a[i]);
    }

System.out.print(" \n ");



    }
}


Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s