MCPcopy Create free account
hub / github.com/QMHTMY/RustBook / move_down

Method move_down

publication/code/chapter08/binary_heap.rs:125–142  ·  view source on GitHub ↗

大数据下沉 l(left), r(right)

(&mut self, mut c: usize)

Source from the content-addressed store, hash-verified

123
124 // 大数据下沉 l(left), r(right)
125 fn move_down(&mut self, mut c: usize) {
126 loop {
127 // 计算当前节点的左子节点位置
128 let lc = left_child!(c);
129 if lc > self.size { break; }
130
131 // 计算当前节点最小子节点位置
132 let mc = self.min_child(c);
133
134 // 当前节点数据大于最小子节点数据,交换
135 if self.data[c] > self.data[mc] {
136 self.data.swap(c, mc);
137 }
138
139 // 最小子节点成为当前节点
140 c = mc;
141 }
142 }
143
144 // 计算最小子节点位置
145 fn min_child(&self, c: usize) -> usize {

Callers 2

build_newMethod · 0.45
popMethod · 0.45

Calls 1

min_childMethod · 0.45

Tested by

no test coverage detected