Selection Sort in Jeliot

Posted by Didi Setyapramana On 8:42 AM 0 komentar

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 ");



    }
}

Categories:

0 Response for the "Selection Sort in Jeliot"

Post a Comment