二叉树遍历(前序)
void PreOrder(TreeNode *root) { TreeNode *p = root; stack<TreeNode*> s; while (!s.empty() || p) { while (p) { cout << p->val << endl; s.push(p); p = p->left; } if (!s.empty()) { p = s.top(); s.pop(); p = p->right; } } }
posted on 2017-09-18 16:17 www_practice 阅读(154) 评论(0) 编辑 收藏 举报