/*
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<TreeNode *>que;
        que.push(pRoot);
        int level = 0; 
        while(!que.empty()) {
            int size = que.size();
            vector<int>vec;
            level++;
            while(size--) {
                TreeNode *front = que.front();
                que.pop();
                vec.push_back(front->val);
                if (front->left) {
                    que.push(front->left);
                }
                if (front->right) {
                    que.push(front->right);
                }
            }
            if (level % 2 == 0) {
                reverse(vec.begin(), vec.end());
            }
            ret.push_back(vec);
        }
        /*
      for(int i = 0; i < ret.size(); i++) {
        if (i % 2 == 1) {
            reverse(ret[i].begin(), ret[i].end());
        }
    }
    */
        return ret;
    }
    
};