QMHTMY / RustBook

A book about Rust Data Structures and Algorithms.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`heap_sort` 结果异常

sukanka opened this issue · comments

使用的代码为 https://github.com/QMHTMY/RustBook/blob/8c6ef29bc84672e37ca4d6b90aafccba10e9b6da/code/chapter06/heap_sort.rs
其中, main 函数略有不同 (删掉 nums 开头的 0

fn main() {
    let mut nums = [ 54, 32, 99, 18, 75, 31, 43, 56, 21, 22];
    heap_sort(&mut nums);
    println!("sorted nums: {:?}", nums);
}

输出结果为

sorted nums: [54, 18, 21, 22, 31, 32, 43, 56, 75, 99]

期望的结果为

sorted nums: [18, 21, 22, 31, 32, 43, 54, 56, 75, 99]