/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
void preorder(struct TreeNode* root, int* res, int* resSize) {
if (root == NULL) {
return;
}
preorder(root->left, res, resSize);//左
res[(*resSize)++] = root->val;//根
preorder(root->right, res, resSize);/右
}
int* preorderTraversal(struct TreeNode* root, int* returnSize) {
int* res = malloc(sizeof(int) * 2000);
*returnSize = 0;
preorder(root, res, returnSize);
return res;
}
Day19二叉树的中序遍历
最新推荐文章于 2024-09-15 16:31:43 发布