mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
Update 0701.二叉搜索树中的插入操作.md
添加代码高亮
This commit is contained in:
@ -59,7 +59,7 @@
|
||||
|
||||
代码如下:
|
||||
|
||||
```
|
||||
```cpp
|
||||
TreeNode* insertIntoBST(TreeNode* root, int val)
|
||||
```
|
||||
|
||||
@ -69,7 +69,7 @@ TreeNode* insertIntoBST(TreeNode* root, int val)
|
||||
|
||||
代码如下:
|
||||
|
||||
```
|
||||
```cpp
|
||||
if (root == NULL) {
|
||||
TreeNode* node = new TreeNode(val);
|
||||
return node;
|
||||
@ -88,7 +88,7 @@ if (root == NULL) {
|
||||
|
||||
代码如下:
|
||||
|
||||
```
|
||||
```cpp
|
||||
if (root->val > val) root->left = insertIntoBST(root->left, val);
|
||||
if (root->val < val) root->right = insertIntoBST(root->right, val);
|
||||
return root;
|
||||
@ -120,7 +120,7 @@ public:
|
||||
|
||||
那么递归函数定义如下:
|
||||
|
||||
```
|
||||
```cpp
|
||||
TreeNode* parent; // 记录遍历节点的父节点
|
||||
void traversal(TreeNode* cur, int val)
|
||||
```
|
||||
|
Reference in New Issue
Block a user