Upload files to "/"
This commit is contained in:
		
							parent
							
								
									5f9aee4374
								
							
						
					
					
						commit
						03424d6cd8
					
				
							
								
								
									
										73
									
								
								MainActivity.kt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										73
									
								
								MainActivity.kt
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,73 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					    Nama: Rafi Fattan Fitriardi
 | 
				
			||||||
 | 
					    NPM : 202310715002
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					package com.example.sorting
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import android.os.Bundle
 | 
				
			||||||
 | 
					import androidx.activity.ComponentActivity
 | 
				
			||||||
 | 
					import androidx.activity.compose.setContent
 | 
				
			||||||
 | 
					import androidx.compose.foundation.layout.*
 | 
				
			||||||
 | 
					import androidx.compose.material3.*
 | 
				
			||||||
 | 
					import androidx.compose.runtime.*
 | 
				
			||||||
 | 
					import androidx.compose.ui.Modifier
 | 
				
			||||||
 | 
					import androidx.compose.ui.tooling.preview.Preview
 | 
				
			||||||
 | 
					import androidx.compose.ui.unit.dp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class MainActivity : ComponentActivity() {
 | 
				
			||||||
 | 
					    override fun onCreate(savedInstanceState: Bundle?) {
 | 
				
			||||||
 | 
					        super.onCreate(savedInstanceState)
 | 
				
			||||||
 | 
					        setContent {
 | 
				
			||||||
 | 
					            BubbleSortApp()
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Composable
 | 
				
			||||||
 | 
					fun BubbleSortApp() {
 | 
				
			||||||
 | 
					    // Array awal
 | 
				
			||||||
 | 
					    val original = listOf(8, 3, 5, 2, 9)
 | 
				
			||||||
 | 
					    val sorted = bubbleSort(original.toMutableList())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Tampilan UI
 | 
				
			||||||
 | 
					    Column(
 | 
				
			||||||
 | 
					        modifier = Modifier
 | 
				
			||||||
 | 
					            .fillMaxSize()
 | 
				
			||||||
 | 
					            .padding(16.dp)
 | 
				
			||||||
 | 
					    ) {
 | 
				
			||||||
 | 
					        Text(
 | 
				
			||||||
 | 
					            text = "Algoritma Bubble Sort",
 | 
				
			||||||
 | 
					            style = MaterialTheme.typography.headlineSmall
 | 
				
			||||||
 | 
					        )
 | 
				
			||||||
 | 
					        Spacer(modifier = Modifier.height(16.dp))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        Text("Sebelum Sorting: ${original.joinToString()}")
 | 
				
			||||||
 | 
					        Spacer(modifier = Modifier.height(8.dp))
 | 
				
			||||||
 | 
					        Text("Sesudah Sorting: ${sorted.joinToString()}")
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					fun bubbleSort(arr: MutableList<Int>): List<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 elemen
 | 
				
			||||||
 | 
					                val temp = arr[j]
 | 
				
			||||||
 | 
					                arr[j] = arr[j + 1]
 | 
				
			||||||
 | 
					                arr[j + 1] = temp
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    return arr
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Preview(showBackground = true)
 | 
				
			||||||
 | 
					@Composable
 | 
				
			||||||
 | 
					fun PreviewBubbleSortApp() {
 | 
				
			||||||
 | 
					    BubbleSortApp()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										
											BIN
										
									
								
								Tugas 2.PNG
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Tugas 2.PNG
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 5.2 KiB  | 
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user