|
|
@ -14,17 +14,16 @@ fn greaterThan(context: void, a: i32, b: i32) std.math.Order {
|
|
|
|
return lessThan(context, a, b).invert();
|
|
|
|
return lessThan(context, a, b).invert();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn testPush(comptime T: type, mem_allocator: std.mem.Allocator, heap_push: anytype, val: T) !void {
|
|
|
|
fn testPush(comptime T: type, mem_allocator: std.mem.Allocator, heap: anytype, val: T) !void {
|
|
|
|
var heap = heap_push;
|
|
|
|
|
|
|
|
try heap.add(val); //元素入堆
|
|
|
|
try heap.add(val); //元素入堆
|
|
|
|
std.debug.print("\n元素 {} 入堆后\n", .{val});
|
|
|
|
std.debug.print("\n元素 {} 入堆后\n", .{val});
|
|
|
|
try inc.PrintUtil.printHeap(T, mem_allocator, heap);
|
|
|
|
try inc.PrintUtil.printHeap(T, mem_allocator, heap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn testPop(comptime T: type, mem_allocator: std.mem.Allocator, heap_pop: anytype) !void {
|
|
|
|
fn testPop(comptime T: type, mem_allocator: std.mem.Allocator, heap: anytype) !void {
|
|
|
|
var val = heap_pop.remove(); //堆顶元素出堆
|
|
|
|
var val = heap.remove(); //堆顶元素出堆
|
|
|
|
std.debug.print("\n堆顶元素 {} 出堆后\n", .{val});
|
|
|
|
std.debug.print("\n堆顶元素 {} 出堆后\n", .{val});
|
|
|
|
try inc.PrintUtil.printHeap(T, mem_allocator, heap_pop);
|
|
|
|
try inc.PrintUtil.printHeap(T, mem_allocator, heap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Driver Code
|
|
|
|
// Driver Code
|
|
|
|