Update binary_search_tree.zig
This commit is contained in:
parent
838b93b36f
commit
b9d3cb1e2c
@ -34,7 +34,7 @@ pub fn BinarySearchTree(comptime T: type) type {
|
|||||||
fn buildTree(self: *Self, nums: []T, i: usize, j: usize) !?*inc.TreeNode(T) {
|
fn buildTree(self: *Self, nums: []T, i: usize, j: usize) !?*inc.TreeNode(T) {
|
||||||
if (i > j) return null;
|
if (i > j) return null;
|
||||||
// 将数组中间节点作为根节点
|
// 将数组中间节点作为根节点
|
||||||
var mid = i + (j - i) / 2;
|
var mid = i + (j - i) / 2;
|
||||||
var node = try self.mem_allocator.create(inc.TreeNode(T));
|
var node = try self.mem_allocator.create(inc.TreeNode(T));
|
||||||
node.init(nums[mid]);
|
node.init(nums[mid]);
|
||||||
// 递归建立左子树和右子树
|
// 递归建立左子树和右子树
|
||||||
|
Loading…
Reference in New Issue
Block a user