MCPcopy Create free account
hub / github.com/douchuan/algorithm / sort

Function sort

src/sort/selection.rs:8–23  ·  view source on GitHub ↗

选择排序 从待排序的数据元素中选出最小(或最大)的一个元素, 然后放到已排序的序列的末尾,直到全部待排序的数据元素的个数为零。 选择排序是不稳定的排序方法

(a: &mut [T])

Source from the content-addressed store, hash-verified

6//! 选择排序是不稳定的排序方法
7
8pub fn sort<T>(a: &mut [T])
9where
10 T: Ord,
11{
12 let len = a.len();
13 for i in 0..len {
14 let mut m = i;
15 for j in (i + 1)..len {
16 if a[m] > a[j] {
17 m = j;
18 }
19 }
20
21 a.swap(i, m);
22 }
23}
24
25/// 鸡尾酒排序 (Cock-tail sort)
26/// 每次扫描可以同时查找最小值和最大值,将最小值放到开头,

Callers

nothing calls this directly

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected