Update the section of heap.

This commit is contained in:
krahets
2023-05-25 20:25:19 +08:00
parent b9178bc7d6
commit 11c835d79c
36 changed files with 22 additions and 24 deletions

View File

@ -48,10 +48,8 @@ pub fn MaxHeap(comptime T: type) type {
// 交换元素
fn swap(self: *Self, i: usize, j: usize) !void {
var a = self.max_heap.?.items[i];
var b = self.max_heap.?.items[j];
var tmp = a;
try self.max_heap.?.replaceRange(i, 1, &[_]T{b});
var tmp = self.max_heap.?.items[i];
try self.max_heap.?.replaceRange(i, 1, &[_]T{self.max_heap.?.items[j]});
try self.max_heap.?.replaceRange(j, 1, &[_]T{tmp});
}