add zig codes for Section Binary Tree, Binary Search Tree and AVL Tree (#293)

* add zig codes for Section 'Binary Tree'

* add zig codes for Section 'Binary Tree'

* add zig codes for Section 'Binary Tree'

* add zig codes for Section 'Binary Tree'

* add zig codes for Section 'Binary Tree' and 'Binary Search Tree'

* update zig codes for Section 'Binary Tree' and 'Binary Search Tree'

* update zig codes for Section 'Binary Tree', 'Binary Search Tree' and 'AVL Tree'
This commit is contained in:
sjinzh
2023-01-28 00:47:58 +08:00
committed by GitHub
parent 3858048d0f
commit b951eb0cfc
5 changed files with 566 additions and 3 deletions

View File

@@ -10,13 +10,15 @@ pub fn TreeNode(comptime T: type) type {
return struct {
const Self = @This();
val: T = undefined,
left: ?*Self = null,
right: ?*Self = null,
val: T = undefined, // 结点值
height: i32 = 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;
self.height = 0;
self.left = null;
self.right = null;
}