标签:
https://leetcode.com/problems/binary-tree-inorder-traversal/
递归中序遍历
1 /** 2 * Definition for a binary tree node. 3 * struct TreeNode { 4 * int val; 5 * TreeNode *left; 6 * TreeNode *right; 7 * TreeNode(int x) : val(x), left(NULL), right(NULL) {} 8 * }; 9 */ 10 class Solution { 11 public: 12 vector<int> inorderTraversal(TreeNode* root) { 13 vector<int> res; 14 inorderVisit(root,res); 15 return res; 16 17 } 18 void inorderVisit(TreeNode * temp,vector<int>& res) 19 { 20 if(temp==NULL) 21 return; 22 if(temp->left!=NULL) 23 inorderVisit(temp->left,res); 24 res.push_back(temp->val); 25 if(temp->right!=NULL) 26 inorderVisit(temp->right,res); 27 } 28 };
标签:
原文地址:http://www.cnblogs.com/aguai1992/p/4636138.html