Created
November 11, 2018 10:05
-
-
Save liuxiaochuang/599e2124ce15b7d0e54cf578eb5cc284 to your computer and use it in GitHub Desktop.
Tree mid visit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void root_medium(TreeNode* root) {//中序,这个难 | |
cout<<"中序遍历:"; | |
stack<TreeNode* > sta; | |
TreeNode * p = root; | |
while(sta.size() || p) { | |
while(p) { | |
sta.push(p); | |
p = p->left; | |
} | |
if (sta.size()) { | |
// TreeNode * top = sta.top(); | |
p = sta.top(); | |
sta.pop(); | |
cout<<p->val<<" "; | |
p = p->right;//hard here | |
} | |
} | |
cout<<endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment