这个题目用队列做,非常简单
1 充分利用了队列先入先出的概念
2 递归的终止条件就是‘if (seq.size())’的size,其为0时,不会进一步递归。
void _seqTreeBylevel(queue<TreeNode *> &seq)
{
int size = seq.size();
for (int i = 0; i < size; ++i)
{
TreeNode * t = seq.front();
cout << t->val << " ";
seq.pop();
if (t->left)
seq.push(t->left);
if (t->right)
seq.push(t->right);
}
if (seq.size())