PROGRAM JAVA MENGURUTKAN BILANGAN DESIMAT DARI KECI KE BESAR, DENGAN ALGORITNA BUBBLESORT
public class urut_bilang_desimal {
public static void main(String[] args) {
int unsortedArray[] = {10, 97, 6, 23, 0, -45, 697, -1000, 1, 0};
int i;
bubbleSort(unsortedArray, unsortedArray.length);
System.out.println("Setellah prose pengurutan : ");
for(i=0; i<unsortedArray.length; i++) {
System.out.print(unsortedArray[i] + " ");
}
}
private static void bubbleSort(int[] unsortedArray, int length) {
int temp, counter, index;
for(counter=0; counter<length-1; counter++) {
for(index=0; index<length-1-counter; index++) {
if(unsortedArray[index] > unsortedArray[index+1]) {
temp = unsortedArray[index];
unsortedArray[index] = unsortedArray[index+1];
unsortedArray[index+1] = temp;
}
}
}
}
}
Nah ini hasil program setelah di jalankan :
Sekian, semoga membantu. :D
I love Coding. Aseeek.