lintcode 二叉树中序遍历

 1 /**
 2  * Definition of TreeNode:
 3  * class TreeNode {
 4  * public:
 5  *     int val;
 6  *     TreeNode *left, *right;
 7  *     TreeNode(int val) {
 8  *         this->val = val;
 9  *         this->left = this->right = NULL;
10  *     }
11  * }
12  */
13  //递归方法
14 class Solution {
15     /**
16      * @param root: The root of binary tree.
17      * @return: Inorder in vector which contains node values.
18      */
19 public:
20 
21     void inorder(TreeNode *root, vector<int> &result) {
22         if (root->left != NULL) {
23             inorder(root->left, result);
24         }
25         
26         result.push_back(root->val);
27         
28         if (root->right != NULL) {
29             inorder(root->right, result);
30         }
31         
32     }
33     
34     vector<int> inorderTraversal(TreeNode *root) {
35         // write your code here
36         vector<int> result;
37         if (root == NULL) 
38             return result;
39         inorder(root, result);
40         return result;
41     }
42 };
原文地址:https://www.cnblogs.com/gousheng/p/7391246.html