Last active
December 31, 2022 08:17
-
-
Save Elerphore/c6347d3e65d9bfac3f38d4de3e1596ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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