Binary Tree inOrder Traversal
struct TreeNode{ int val; TreeNode *left; TreeNode *right; TreeNode(int x):val(x),left(NULL),right(NULL){}; }; class Solution{ public: vector<int>inorderTraversal(TreeNode *root) { vector<int>inOrder; Traversal(root,inOrder); return inOrder; } stack<TreeNode*> st; private: void Traversal(TreeNode *root,vector<int>&inOrder) { if(root==NULL) return; TreeNode *p; TreeNode *pre=NULL; bool flag=true; p=root; while(p||!st.empty()) { if(p) { st.push(p); p=p->left; } else { p=st.top(); st.pop(); inOrder.push_back(p->val); p=p->right; } } } };