递归遍历
重点:
1,TreeNode的自定义
2,val =0 == val = NULL;
代码:
1 void preRecursor(TreeNode* root, vector<int>& result) 2 { 3 if (root == NULL) 4 return; 5 result.push_back(root->val); 6 preRecursor(root->left, result); 7 preRecursor(root->right, result); 8 } 9 10 vector<int> preorderTraversal(TreeNode* root) 11 { 12 vector<int> result; 13 preRecursor(root, result); 14 return result; 15 }
标签:preRecursor,遍历,TreeNode,迭代,随想录,result,root From: https://www.cnblogs.com/smartisn/p/17492929.html