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 class Solution {
14 /**
15 * @param root: The root of binary tree.
16 * @return: Inorder in vector which contains node values.
17 */
18 public:
19 vector<int> inorderTraversal(TreeNode *root) {
20 // write your code here
21 vector<int> order;
22 if(root == NULL)
23 return order;
24
25 stack<TreeNode*> s;
26 TreeNode *p=root;
27 while(p!=NULL||!s.empty()) {
28 while(p!=NULL) {
29 s.push(p);
30 p=p->left;
31 }
32 if(!s.empty()) {
33 p=s.top();
34 order.push_back(p->val);
35 s.pop();
36 p=p->right;
37 }
38 }
39 return order;
40 }
41 };