2023-01-09 19:31:45 +08:00
|
|
|
// File: TreeNode.zig
|
|
|
|
// Created Time: 2023-01-07
|
|
|
|
// Author: sjinzh (sjinzh@gmail.com)
|
|
|
|
|
|
|
|
const std = @import("std");
|
|
|
|
|
|
|
|
// Definition for a binary tree node
|
2023-01-10 17:19:21 +08:00
|
|
|
// 编译期泛型
|
2023-01-09 19:31:45 +08:00
|
|
|
pub fn TreeNode(comptime T: type) type {
|
|
|
|
return struct {
|
|
|
|
const Self = @This();
|
|
|
|
|
|
|
|
val: T = undefined,
|
|
|
|
left: ?*Self = null,
|
|
|
|
right: ?*Self = null,
|
|
|
|
|
|
|
|
// Initialize a tree node with specific value
|
|
|
|
pub fn init(self: *Self, x: i32) void {
|
|
|
|
self.val = x;
|
2023-01-13 23:40:37 +08:00
|
|
|
self.left = null;
|
|
|
|
self.right = null;
|
2023-01-09 19:31:45 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|