1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

struct TreeNode {
     int val;
     TreeNode *left;
     TreeNode *right;
     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 };

void inorderTraversal(TreeNode *n, vector<int>& result) 
{
    if (n == NULL) return;

    inorderTraversal(n->left, result);
    result.push_back(n->val);
    inorderTraversal(n->right, result);
}

vector<int> inorderTraversal(TreeNode *root) 
{
    vector<int> result;
    inorderTraversal(root, result);
    return result;
}
View Program Text


Test Status