Skip to content

Instantly share code, notes, and snippets.

@liuxiaochuang
Created November 11, 2018 10:05
Show Gist options
  • Save liuxiaochuang/599e2124ce15b7d0e54cf578eb5cc284 to your computer and use it in GitHub Desktop.
Save liuxiaochuang/599e2124ce15b7d0e54cf578eb5cc284 to your computer and use it in GitHub Desktop.
Tree mid visit
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