Skip to content

Instantly share code, notes, and snippets.

@Elerphore
Last active December 31, 2022 08:17
Show Gist options
  • Select an option

  • Save Elerphore/c6347d3e65d9bfac3f38d4de3e1596ed to your computer and use it in GitHub Desktop.

Select an option

Save Elerphore/c6347d3e65d9bfac3f38d4de3e1596ed to your computer and use it in GitHub Desktop.
data class ShittyChar(val char: Char, val pos: Int)
fun main() {
val symbols = mutableListOf(
ShittyChar('a', 0),
ShittyChar('A', 3),
ShittyChar('b', 0),
ShittyChar('A', 1),
ShittyChar('B', 0),
ShittyChar('A', 2),
)
val arr_length = symbols.size
var swapSucceeded = false
inner@ for(i in 0 until arr_length - 1) {
swapSucceeded = false
for (j in 0 until arr_length - 1 - i) {
if (symbols[j].char.code > symbols[j + 1].char.code) {
swap(symbols, j, j + 1)
swapSucceeded = true
}
}
if (!swapSucceeded) {
break@inner
}
}
symbols.forEach(::println)
}
fun swap(array: MutableList<ShittyChar>, i: Int, j: Int) {
val temp = array[i]
array[i] = array[j]
array[j] = temp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment