# quickselect **Repository Path**: ArkTSCentralRepository/quickselect ## Basic Information - **Project Name**: quickselect - **Description**: quickselect 是一种高效的选择算法,使用Floyd-Rivest选择算法在数组中找到第k个最小元素并对部分数组进行排序,现已适配为ArkTS文件。 - **Primary Language**: Unknown - **License**: ISC - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-11-21 - **Last Updated**: 2024-11-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # quickselect 基于[quickselect](https://www.npmjs.com/package/quickselect)原库3.0.0版本进行适配, 所有功能代码已经转换为`ArkTS`文件 ## Install ```sh ohpm install quickselect ``` ## Description A tiny and fast [selection algorithm](https://en.wikipedia.org/wiki/Selection_algorithm) in ArkTS (specifically, [Floyd-Rivest selection](https://en.wikipedia.org/wiki/Floyd%E2%80%93Rivest_algorithm)). ```typescript quickselect(array, k, left, right, compareFn); ``` Rearranges items so that all items in the `[left, k]` are the smallest. The `k`-th element will have the `(k - left + 1)`-th smallest value in `[left, right]`. - `array`: the array to partially sort (in place) - `k`: middle index for partial sorting (as defined above) - `left`: left index of the range to sort (`0` by default) - `right`: right index (last index of the array by default) - `compareFn`: compare function Example: ```typescript import quickselect from 'quickselect'; const arr = [65, 28, 59, 33, 21, 56, 22, 95, 50, 12, 90, 53, 28, 77, 39]; quickselect(arr, 8); // arr is [39, 28, 28, 33, 21, 12, 22, 50, 53, 56, 59, 65, 90, 77, 95] // ^^ middle index ```