/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package bubblesort;
/**
*
* @author Angga
*/
public class bubbleSort {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int unsortedArray[] = {10, 97, 6, 23, 0, -45, 697, -1000, 1, 0};
int i;
System.out.println(“Sebelum sorting, elemen-elemenya adalah :”);
for(i=0; i<unsortedArray.length; i++) { // perulangan untuk mencetak array
System.out.print(unsortedArray[i] + " "); // mencetak array sebelum disorting
}
System.out.println("\n"); // membuat baris kosong
bubbleSort(unsortedArray, unsortedArray.length);
System.out.println("Setelah sorting,elemen-elemenya menjadi : ");
for(i=0; i<unsortedArray.length; i++) {
System.out.print(unsortedArray[i] + " ");
}
System.out.println("\n"); // membuat baris kosong
}
//———————————————————————–
private static void bubbleSort(int[] unsortedArray, int length) {
int temp, counter, index;
for(counter=0; counter<length-1; counter++) {
for(index=0; index unsortedArray[index+1]) {
temp = unsortedArray[index];
unsortedArray[index] = unsortedArray[index+1];
unsortedArray[index+1] = temp;
}
}
}
}
}