Sorting algorithms/Insertion sort: Difference between revisions
Content added Content deleted
(→{{header|Kotlin}}: Add Kotlin alternative solution) |
|||
Line 3,398:
Sorted: [1, 2, 3, 3, 4, 5, 7, 8, 9, 12, 17]</pre>
===Alternative solution, optimized using binary search===
Similar concept to C++ solution. This solution uses a hand-written algorithm to find the upper bound as there is no Kotlin/Java equivalent to C++'s `std::upper_bound`. Thus this function performs a stable sort (unlike the Java solution which uses `binarySearch`)
<syntaxhighlight lang="kotlin">
|