Skip to content

Instantly share code, notes, and snippets.

@5AbhishekSaxena
Created July 15, 2022 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 5AbhishekSaxena/f34ce12cc465a8b2c15ad09f0ebfa8f0 to your computer and use it in GitHub Desktop.
Save 5AbhishekSaxena/f34ce12cc465a8b2c15ad09f0ebfa8f0 to your computer and use it in GitHub Desktop.
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