/*
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);
bool flag = true;
while(!que.empty()) {
int size = que.size();
vector<int>vec;
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);
}
}
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;
}
};