Ed Inteligência Artificial do Passei Direto
há 2 anos
Claro! Aqui está um exemplo de como implementar o algoritmo de Bubble Sort em Kotlin: ```kotlin fun bubbleSort(arr: IntArray) { 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]) { val temp = arr[j] arr[j] = arr[j + 1] arr[j + 1] = temp } } } } fun main() { val arr = intArrayOf(64, 34, 25, 12, 22, 11, 90) bubbleSort(arr) println("Array ordenado:") for (i in arr.indices) { print("${arr[i]} ") } } ``` Neste exemplo, a função `bubbleSort` recebe um array de inteiros e ordena seus elementos em ordem crescente. A função `main` cria um array de exemplo, chama a função `bubbleSort` para ordená-lo e, em seguida, imprime o array ordenado. Espero que isso ajude! Se você tiver mais alguma dúvida, é só perguntar.