/**
* Program : Algoritma pengurutan Bubble Sort
* Date : 4 Juni 2022
* Author : Riyanto
* Website : https://www.melonkoding.com
*/
import java.util.Arrays;
class Main {
private static int[] numbers = {4, 1, 9, 3, 7, 2, 8, 5, 6};
public static void main(String[] args) {
System.out.println("Unsorted : "+ Arrays.toString(numbers));
System.out.println("Sorted Asc: "+ Arrays.toString(bubble(numbers)));
}
private static int[] bubble(int[] numbers) {
for(int i=0; i<numbers.length - 1; i++) {
for(int j=0; j<numbers.length - (i+1); j++) {
if(numbers[j] > numbers[j+1]) {
int temp = numbers[j];
numbers[j] = numbers[j+1];
numbers[j+1] = temp;
}
}
}
return numbers;
}
}