commit e495cd5ec8018ac18adcfbe12bcc91452644a60e Author: 202310715128 ARIF NURKHAYAN <202310715128@mhs.ubharajaya.ac.id> Date: Thu Oct 9 15:01:21 2025 +0700 Upload files to "/" diff --git a/MainActivity.kt b/MainActivity.kt new file mode 100644 index 0000000..4c6ea14 --- /dev/null +++ b/MainActivity.kt @@ -0,0 +1,71 @@ +package com.example.array + +import android.os.Bundle +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.enableEdgeToEdge +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import com.example.array.ui.theme.ArrayTheme + +class MainActivity : ComponentActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + enableEdgeToEdge() + setContent { + ArrayTheme { + Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -> + + // Data awal + val data = arrayOf(19, 15, 1, 14, 3) + val before = data.joinToString(", ") + + // Jalankan insertion sort + insertionSort(data) + val after = data.joinToString(", ") + + Greeting( + text = "Array sebelum: $before\nArray sesudah: $after", + modifier = Modifier.padding(innerPadding) + ) + } + } + } + } + + // Fungsi insertion sort + private fun insertionSort(array: Array) { + for (i in 1 until array.size) { + val key = array[i] + var j = i - 1 + + // Pindahkan elemen yang lebih besar dari key ke satu posisi di depan + while (j >= 0 && array[j] > key) { + array[j + 1] = array[j] + j-- + } + array[j + 1] = key + } + } +} + +@Composable +fun Greeting(text: String, modifier: Modifier = Modifier) { + Text( + text = text, + modifier = modifier + ) +} + +@Preview(showBackground = true) +@Composable +fun GreetingPreview() { + ArrayTheme { + Greeting("Array sebelum: 9, 5, 1, 4, 3\nArray sesudah: 1, 3, 4, 5, 9") + } +} \ No newline at end of file diff --git a/Screenshot 2025-10-09 145856.jpg b/Screenshot 2025-10-09 145856.jpg new file mode 100644 index 0000000..f506f65 Binary files /dev/null and b/Screenshot 2025-10-09 145856.jpg differ