题目
给出一棵二叉树,返回其中序遍历
C++
非递归
vector inorderTraversal(TreeNode *root) { // write your code here vector vec; stacks; 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;}