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

Function sort

src/sort/insert.rs:7–21  ·  view source on GitHub ↗
(a: &mut [T])

Source from the content-addressed store, hash-verified

5use std::cmp::Ordering;
6
7pub fn sort<T>(a: &mut [T])
8where
9 T: Ord,
10{
11 let len = a.len();
12 // i begins with `1`
13 for i in 1..len {
14 // insert a[i] into a[0..i-1]
15 let mut j = i;
16 while j > 0 && a[j] < a[j - 1] {
17 a.swap(j, j - 1);
18 j -= 1;
19 }
20 }
21}
22
23/// insertion sort a[lo..=hi], starting at d-th character
24/// lo & hi, is inclusive

Callers

nothing calls this directly

Calls 1

lenMethod · 0.45

Tested by

no test coverage detected