/**
* Definition for binary tree
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode(int x) : val(x), left(NULL), right(NULL) {}
* };
*/
class Solution {
public:
vector<vector<int> > levelOrderBottom(TreeNode *root) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
stack<vector<int> > mystack;
deque<TreeNode *> queue;
deque<TreeNode *> prequeue;
if(root!=NULL)
queue.push_back(root);
vector<vector<int> > result;
vector<int> temp;
while(queue.size())
{
temp.clear();
prequeue = queue;
queue.clear();
for(deque<TreeNode *>::iterator iter = prequeue.begin();iter!=prequeue.end();iter++)
{
temp.push_back((*iter)->val);
if((*iter)->left!=NULL)
queue.push_back((*iter)->left);
if((*iter)->right!=NULL)
queue.push_back((*iter)->right);
}
mystack.push(temp);
}
while(!mystack.empty())
{
result.push_back(mystack.top());
mystack.pop();
}
return result;
}
};