mirror of
https://github.com/krahets/hello-algo.git
synced 2025-08-02 19:53:11 +08:00
update zig codes for Section 'Heap' (heap.zig)
This commit is contained in:
@ -59,13 +59,16 @@ pub fn printHashMap(comptime TKey: type, comptime TValue: type, map: std.AutoHas
|
||||
}
|
||||
|
||||
// print a heap (PriorityQueue)
|
||||
pub fn printHeap(comptime T: type, mem_allocator: std.mem.Allocator, queue: anytype) !void {
|
||||
pub fn printHeap(comptime T: type, mem_allocator: std.mem.Allocator, queue: anytype, queue_flag: bool) !void {
|
||||
var arr = queue.items;
|
||||
var len = queue.len;
|
||||
std.debug.print("堆的数组表示:", .{});
|
||||
printArray(T, arr[0..len]);
|
||||
std.debug.print("\n堆的树状表示:\n", .{});
|
||||
var root = try TreeUtil.arrToTree(T, mem_allocator, arr[0..len]);
|
||||
var root = if (queue_flag)
|
||||
try TreeUtil.arrQueToTree(T, mem_allocator, arr[0..len]) // through TailQueue
|
||||
else
|
||||
try TreeUtil.arrListToTree(T, mem_allocator, arr[0..len]); // through ArrayList to work as queue
|
||||
try printTree(root, null, false);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user