代码拉取完成,页面将自动刷新
package partial
import (
"cmp"
"slices"
)
// Sort partially sorts a slice of any ordered type in ascending order.
// Only elements in x[:k] will be in sorted order. This is faster than using
// slices.Sort when k is small relative to the number of elements.
func Sort[E cmp.Ordered](x []E, k int) {
k = min(k, len(x))
if k > 0 {
floydRivest(x, 0, len(x)-1, k-1) // 0-indexed
slices.Sort(x[:k-1])
}
}
// SortFunc partially sorts the slice x in ascending order as determined by the
// less function. Only elements in x[:k] will be in sorted order. This is faster
// than using slices.SortFunc when k is small relative to the number of elements.
func SortFunc[E any](x []E, k int, less func(E, E) int) {
k = min(k, len(x))
if k > 0 {
floydRivestFunc(x, 0, len(x)-1, k-1, less)
slices.SortFunc(x[:k-1], less)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。