Files
hello-algo/ru/codes/zig/include/PrintUtil.zig
Yudong Jin 772183705e Add ru version (#1865)
* Add Russian docs site baseline

* Add Russian localized codebase

* Polish Russian code wording

* Update ru code translation.

* Update code translation and chapter covers.

* Fix pythontutor extraction.

* Add README and landing page.

* placeholder of profiles

* Use figures of English version

* Remove chapter paperbook
2026-03-28 04:24:07 +08:00

43 lines
1.5 KiB
Zig

// File: PrintUtil.zig
// Created Time: 2023-01-07
// Author: codingonion (coderonion@gmail.com)
const std = @import("std");
pub const ListUtil = @import("ListNode.zig");
pub const ListNode = ListUtil.ListNode;
pub const TreeUtil = @import("TreeNode.zig");
pub const TreeNode = TreeUtil.TreeNode;
// Вывести очередь
pub fn printQueue(comptime T: type, queue: std.TailQueue(T)) void {
var node = queue.first;
std.debug.print("[", .{});
var i: i32 = 0;
while (node != null) : (i += 1) {
var data = node.?.data;
std.debug.print("{}{s}", .{ data, if (i == queue.len - 1) "]" else ", " });
node = node.?.next;
}
}
// Вывести хеш-таблицу
pub fn printHashMap(comptime TKey: type, comptime TValue: type, map: std.AutoHashMap(TKey, TValue)) void {
var it = map.iterator();
while (it.next()) |kv| {
var key = kv.key_ptr.*;
var value = kv.value_ptr.*;
std.debug.print("{} -> {s}\n", .{ key, value });
}
}
// Вывести кучу
pub fn printHeap(comptime T: type, mem_allocator: std.mem.Allocator, queue: anytype) !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]);
try printTree(root, null, false);
}