Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fun main() {
val numbers = arrayOf(4, 56, 12, 79, 25, 2)
sort("Bubble", numbers)
}
fun sort(algorithm: String, numbers: Array<Int>) {
when (algorithm) {
"Bubble" -> bubbleSort(numbers)
"Merge" -> mergeSort(numbers)
else -> throw IllegalArgumentException()
}
}
fun bubbleSort(numbers: Array<Int>) {
println("Numbers are sorted using Bubble sort.")
}
fun mergeSort(numbers: Array<Int>) {
println("Numbers are sorted using Merge sort.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment