/*
struct TreeNode {
    int val;
    struct TreeNode *left;
    struct TreeNode *right;
    TreeNode(int x) :
            val(x), left(NULL), right(NULL) {
    }
};
*/
class Solution {
public:
    vector<vector<int> > Print(TreeNode* pRoot) {
        vector<vector<int>>ret;
        // 判定输入
        if(!pRoot) {
            return ret;
        }
        // queue 先进先出
        queue<TreeNode*> que;
        que.push(pRoot);
        int count = 0;
        while(!que.empty()) {
            int size = que.size();
            vector<int>vec;
            count++;
            while(size --) {
                // 取出front,将left和right推入队列中
                TreeNode *front = que.front();
                vec.push_back(front->val);
                que.pop();
                if (front->left) {
                    que.push(front->left);
                }
                if (front->right) {
                    que.push(front->right);
                }
            }
            if (count % 2 == 0) {
                reverse(vec.begin(), vec.end());
            }
            ret.push_back(vec);
        }
        return ret;
    }
    
};