findOrderStatistic

fun <T : Comparable<T>> Array<T>.findOrderStatistic(k: Int, from: Int, to: Int, ascending: Boolean): T

Executes K-th order statistic. Average O(N). Swap elements in array. At the end, the K-th element will be under index k.

Return

k-th element from array

Parameters

k

element search ordinal number. 0 <k<= to - from

from

index from for search in array (inclusive)

to

index to for search in array (exclusive)

ascending

if true search in ascending order else in descending order