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

Function sort_desc

src/sort/tree_selection.rs:15–25  ·  view source on GitHub ↗

排序结果:大 -> 小 构建tree的时间复杂度 O(n) 每次pop的时间复杂度 O(log2(n)),所以弹出n个元素的的时间复杂度为 O(n * log2(n))

(data: &[K])

Source from the content-addressed store, hash-verified

13/// 构建tree的时间复杂度 O(n)
14/// 每次pop的时间复杂度 O(log2(n)),所以弹出n个元素的的时间复杂度为 O(n * log2(n))
15pub fn sort_desc<K>(data: &[K]) -> Vec<K>
16where
17 K: Copy + std::cmp::Ord + Minimal,
18{
19 let mut tree: Tree<K, i32> = TreeBuilder::build_tournament_tree(data);
20 let mut r = Vec::with_capacity(data.len());
21 while let Some(v) = TreeBuilder::tournament_tree_pop(&mut tree) {
22 r.push(v);
23 }
24 r
25}

Callers 3

tournament_treeFunction · 0.85

Calls 2

pushMethod · 0.80
lenMethod · 0.45

Tested by 1

tournament_treeFunction · 0.68