问题:二叉树中序遍历
递归实现
/** * 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 InOrder(TreeNode *root,vector<int>&vec) { if(root==NULL) return ; InOrder(root->left,vec); vec.push_back(root->val); InOrder(root->right,vec); } vector<int> inorderTraversal(TreeNode *root) { vector<int>vec; InOrder(root,vec); return vec; } };