二叉树的后序遍历
递归实现
/** * 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 PostOrder(TreeNode* root,vector<int>&vec) { if(root!=NULL) { PostOrder(root->left,vec); PostOrder(root->right,vec); vec.push_back(root->val); } } vector<int> postorderTraversal(TreeNode *root) { vector<int>vec; PostOrder(root,vec); return vec; } };