mirror of
				https://github.com/krahets/hello-algo.git
				synced 2025-11-04 14:18:20 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			22 lines
		
	
	
		
			502 B
		
	
	
	
		
			Zig
		
	
	
	
	
	
			
		
		
	
	
			22 lines
		
	
	
		
			502 B
		
	
	
	
		
			Zig
		
	
	
	
	
	
// File: TreeNode.zig
 | 
						|
// Created Time: 2023-01-07
 | 
						|
// Author: sjinzh (sjinzh@gmail.com)
 | 
						|
 | 
						|
const std = @import("std");
 | 
						|
 | 
						|
// Definition for a binary tree node
 | 
						|
// 编译期泛型
 | 
						|
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;
 | 
						|
        }
 | 
						|
    };   
 | 
						|
} |