parent
a518db03dd
commit
6fdcc59aec
|
|
@ -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)
|
||||
```
|
||||
|
|
|
|||
Loading…
Reference in New Issue