/*
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) {
          if (pRoot == nullptr) {
            return std::vector<std::vector<int>>();
          }
          
          std::vector<std::vector<int>> res;
          std::queue<TreeNode *> s;
          s.push(pRoot);
          
          while (!s.empty()) {
            int size = s.size();
            std::vector<int> tmp;
            
            for (int i = 0; i < size; ++i) {
              TreeNode *root = s.front();
              s.pop();
              tmp.push_back(root->val);
              
              if (root->left) {
                s.push(root->left);
              }
              if (root->right) {
                s.push(root->right);
              }
            }
            
            res.push_back(tmp);
          }
          
          return res;
        }
    
};