update zig codes for Section 'Heap' (my_heap.zig)

pull/262/head
sjinzh 2 years ago
parent 67f5050ca4
commit cb0a3f868d

@ -7,7 +7,7 @@ const inc = @import("include");
//
//
pub fn MyMaxHeap(comptime T: type) type {
pub fn MaxHeap(comptime T: type) type {
return struct {
const Self = @This();
@ -17,7 +17,7 @@ pub fn MyMaxHeap(comptime T: type) type {
pub fn init(self: *Self, allocator: std.mem.Allocator, nums: []const T) !void {
if (self.maxHeap != null) return;
self.maxHeap = std.ArrayList(T).init(allocator);
//
//
try self.maxHeap.?.appendSlice(nums);
//
var i: usize = parent(self.size() - 1) + 1;
@ -155,7 +155,7 @@ pub fn main() !void {
const mem_allocator = mem_arena.allocator();
//
var maxHeap = MyMaxHeap(i32){};
var maxHeap = MaxHeap(i32){};
try maxHeap.init(std.heap.page_allocator, &[_]i32{ 9, 8, 6, 6, 7, 5, 2, 1, 4, 3, 6, 2 });
defer maxHeap.deinit();
std.debug.print("\n输入列表并建堆后\n", .{});

Loading…
Cancel
Save