每层结束会从队列中读到一个Null 并将状态位改变
```
/
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
/
class Solution {
public:
vector[HTML_REMOVED]> printFromTopToBottom(TreeNode root) {
if(!root) return {};
vector[HTML_REMOVED]> res;
vector[HTML_REMOVED] cur;
bool status = true;
queue[HTML_REMOVED] q;
q.push(root);
q.push(NULL);
while(q.size())
{
auto t = q.front();
q.pop();
if(t)
{
cur.push_back(t->val);
if(t->left) q.push(t->left);
if(t->right) q.push(t->right);
}
else
{
if(q.size()) q.push(NULL); status = !status;
if(status) reverse(cur.begin(),cur.end());
res.push_back(cur);
cur.clear();
}
}
return res;
}
};