Fix a comment in binary_search_tree code

pull/506/head
krahets 2 years ago
parent 26cc480ff5
commit 817b4598d5

@ -89,7 +89,7 @@ void insert(binarySearchTree *bst, int num) {
cur = cur->left; cur = cur->left;
} }
} }
// 插入节点 val // 插入节点
TreeNode *node = newTreeNode(num); TreeNode *node = newTreeNode(num);
if (pre->val < num) { if (pre->val < num) {
pre->right = node; pre->right = node;

@ -77,7 +77,7 @@ class BinarySearchTree {
else else
cur = cur->left; cur = cur->left;
} }
// 插入节点 val // 插入节点
TreeNode *node = new TreeNode(num); TreeNode *node = new TreeNode(num);
if (pre->val < num) if (pre->val < num)
pre->right = node; pre->right = node;

@ -63,7 +63,7 @@ class BinarySearchTree {
else cur = cur.left; else cur = cur.left;
} }
// 插入节点 val // 插入节点
TreeNode node = new TreeNode(num); TreeNode node = new TreeNode(num);
if (pre != null) { if (pre != null) {
if (pre.val < num) pre.right = node; if (pre.val < num) pre.right = node;

@ -70,7 +70,7 @@ void insert(int num) {
else else
cur = cur.left; cur = cur.left;
} }
// val //
TreeNode? node = TreeNode(num); TreeNode? node = TreeNode(num);
if (pre!.val < num) if (pre!.val < num)
pre.right = node; pre.right = node;

@ -74,7 +74,7 @@ class BinarySearchTree {
else else
cur = cur.left; cur = cur.left;
} }
// 插入节点 val // 插入节点
TreeNode node = new TreeNode(num); TreeNode node = new TreeNode(num);
if (pre.val < num) if (pre.val < num)
pre.right = node; pre.right = node;

@ -66,7 +66,7 @@ function insert(num) {
// 插入位置在 cur 的左子树中 // 插入位置在 cur 的左子树中
else cur = cur.left; else cur = cur.left;
} }
// 插入节点 val // 插入节点
let node = new TreeNode(num); let node = new TreeNode(num);
if (pre.val < num) pre.right = node; if (pre.val < num) pre.right = node;
else pre.left = node; else pre.left = node;

@ -77,7 +77,7 @@ class BinarySearchTree:
else: else:
cur = cur.left cur = cur.left
# 插入节点 val # 插入节点
node = TreeNode(num) node = TreeNode(num)
if pre.val < num: if pre.val < num:
pre.right = node pre.right = node

@ -80,7 +80,7 @@ class BinarySearchTree {
cur = cur?.left cur = cur?.left
} }
} }
// val //
let node = TreeNode(x: num) let node = TreeNode(x: num)
if pre!.val < num { if pre!.val < num {
pre?.right = node pre?.right = node

@ -71,7 +71,7 @@ function insert(num: number): void {
cur = cur.left as TreeNode; // 插入位置在 cur 的左子树中 cur = cur.left as TreeNode; // 插入位置在 cur 的左子树中
} }
} }
// 插入节点 val // 插入节点
let node = new TreeNode(num); let node = new TreeNode(num);
if (pre!.val < num) { if (pre!.val < num) {
pre!.right = node; pre!.right = node;

@ -87,7 +87,7 @@ pub fn BinarySearchTree(comptime T: type) type {
cur = cur.?.left; cur = cur.?.left;
} }
} }
// val //
var node = try self.mem_allocator.create(inc.TreeNode(T)); var node = try self.mem_allocator.create(inc.TreeNode(T));
node.init(num); node.init(num);
if (pre.?.val < num) { if (pre.?.val < num) {

Loading…
Cancel
Save