3 ms·
Java is an interesting one; while you don't write the sorting algorithm, you do write the sorting conditions, a function that returns a number depending on the
by Cthulhu_ 6y ago
Java is an interesting one; while you don't write the sorting algorithm, you do write the sorting conditions, a function that returns a number depending on the compared values. Likewise there's hash functions, although in practice those will be generated by your IDE or Lombok. (I haven't been into Java for a while so there may be better alternatives, iirc Scala and / or Kotlin solve it as well)
- ajuc 6y agoMost of the time instead of writing or even using sort you're better off using a sorting collection like TreeSet or TreeMap. No need to sort everything again after adding 1 element.