Pages

Minggu, 30 Oktober 2011

Bubble Search

Kelas Larik

package search;


public class LarikBuble {
public static void bubleSOrt (int x[]){
    for (int iterasi = 1; iterasi <= x.length-1; iterasi++) {
        for (int elemen = 0; elemen <= x.length-1-iterasi; elemen++) {
            if (x[elemen]>x[elemen]){
                //menukarkan isi x[elemen] dengan x[elemen+1]
                int temp = x[elemen];
                x[elemen]=x[elemen+1];
                x[elemen+1]=temp;
            }

        }

    }
}
}



Kelas Main


package search;

import java.util.Scanner;

/**
 *
 * @author admin
 */
public class MainBuble {
    public static void main(String[] args) {
        Scanner x=new Scanner(System.in);
        int data[]={1,2,3,4,5,6,7,8,9,0};

        LarikBuble.bubleSOrt(data);
        for (int i = 0; i < data.length; i++) {
            System.out.println(data[i]);

        }

    }

}

0 komentar:

Posting Komentar