class Solution {
public:
    vector<vector<int> > Print(TreeNode* pRoot) {
        vector<vector<int>> ans;
        if(!pRoot) return ans;
        queue<TreeNode*> q;
        q.push(pRoot);
        int n,i,step=0;
        TreeNode* t;
        while(!q.empty())
        {
            n = q.size();
            vector<int> tmp;
            for(i=0;i<n;i++)
            {
                t = q.front();
                tmp.push_back(t->val);
                q.pop();
                if(t->left) q.push(t->left);
                if(t->right) q.push(t->right);
            }
            step++;
            if(step%2==0) reverse(tmp.begin(), tmp.end());
            ans.push_back(tmp);
        }
        return ans;
    }
};