Skip to content

Instantly share code, notes, and snippets.

@SanjayDevTech
Created June 29, 2021 11:43
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 SanjayDevTech/4afc3fa1886bf48060d3599f09e779f6 to your computer and use it in GitHub Desktop.
Save SanjayDevTech/4afc3fa1886bf48060d3599f09e779f6 to your computer and use it in GitHub Desktop.
Kotlin sort list
fun main() {
val elements = mutableListOf(51, 21, 32, 41, 0, 10, 2, 7)
for (i in 0 until elements.size) {
for (j in 1 until elements.size) {
if (elements[j-1] > elements[j]) {
val temp = elements[j]
elements[j] = elements[j - 1]
elements[j-1] = temp
}
}
}
println(elements)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment