Upload files to "/"

This commit is contained in:
202310715083 RAKHA ADI SAPUTRO 2025-10-09 09:37:00 +07:00
commit afb529bb62

26
bubblesort.kt Normal file
View File

@ -0,0 +1,26 @@
fun main() {
// Data awal
val numbers = arrayOf(64, 34, 25, 12, 22, 11, 90)
println("Sebelum Sorting: ${numbers.joinToString(", ")}")
// Panggil fungsi bubbleSort
bubbleSort(numbers)
println("Sesudah Sorting: ${numbers.joinToString(", ")}")
}
// Fungsi Bubble Sort
fun bubbleSort(arr: Array<Int>) {
val n = arr.size
for (i in 0 until n - 1) {
for (j in 0 until n - i - 1) {
if (arr[j] > arr[j + 1]) {
// Tukar posisi
val temp = arr[j]
arr[j] = arr[j + 1]
arr[j + 1] = temp
}
}
}
}