Berhubung beberapa waktu lalu ada tugas bikin program sorting berbasis GUI, Kali ini iwoen mau share coding selection sort pemrograman java. Dan berikut ini coding programnya :
SelectionSort.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
int[] x;
x = new int[MData.size()];
for(int i=0;i<MData.size();i++){
x[i] = Integer.parseInt(MData.get(i).toString());
}
MIterasi.clear();
logs("Selection Sort");
int tampung;
for(int i=0;i<x.length-1;i++){
logs("Iterasi Ke-"+ (i+1));
String stmp = "";for(int a=0; a<x.length;a++){stmp = stmp + x[a] + " ";}
logs(stmp);
// Rumus Selection sort
int minindek = i+1;
for(int j=minindek+1; j<x.length;j++){
if(x[j] < x[minindek]){
minindek = j;
}
if(x[minindek]<x[i]){
tampung=x[i];
x[i]=x[minindek];
x[minindek]=tampung;
}
stmp = "";
for(int a=0; a<x.length;a++){stmp = stmp + x[a] + " ";};logs(stmp);
}
}
}
});
{ 1 Comments... Views All / Post Comment! }
thank'z atas info ny ........
Post a Comment