Merge pull request #1237 from Guacker/master

修改_474_lines_(402_sloc)_e二叉树的递归遍历_c语言前序遍历
This commit is contained in:
程序员Carl
2022-05-07 09:25:17 +08:00
committed by GitHub

View File

@ -371,18 +371,18 @@ C:
```c
//前序遍历:
void preOrderTraversal(struct TreeNode* root, int* ret, int* returnSize) {
void preOrder(struct TreeNode* root, int* ret, int* returnSize) {
if(root == NULL)
return;
ret[(*returnSize)++] = root->val;
preOrderTraverse(root->left, ret, returnSize);
preOrderTraverse(root->right, ret, returnSize);
preOrder(root->left, ret, returnSize);
preOrder(root->right, ret, returnSize);
}
int* preorderTraversal(struct TreeNode* root, int* returnSize){
int* ret = (int*)malloc(sizeof(int) * 100);
*returnSize = 0;
preOrderTraversal(root, ret, returnSize);
preOrder(root, ret, returnSize);
return ret;
}