题目链接:Binary Tree PostOrder Trveral题目意思: 给定一棵二叉树,求后续遍历序列代码:/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
void getPostOrder (TreeNode *root, vector& output);
vectorpostorderTraversal(TreeNode *root);
};
void Solution::getPostOrder(TreeNode *root, vector& output) {
if (NULL == root) {
return;
}
getPostOrder(root->left, output);
getPostOrder(root->right, output);
output.push_back(root->val);
}
...
继续阅读
(20)