标签:
题目
给出一棵二叉树,返回其中序遍历
C++
非递归
vector<int> inorderTraversal(TreeNode *root) { // write your code here vector<int> vec; stack<TreeNode*> s; TreeNode* p; p = root; while (p || !s.empty()) { while(p) { s.push(p); p = p->left; } p = s.top(); vec.push_back(p->val); s.pop(); p = p->right; } return vec; }
标签:
原文地址:http://www.cnblogs.com/Smallhui/p/5449014.html