/************************************************************
Following is the TreeNode class structure
template <typename T>
class TreeNode {
public:
T data;
TreeNode<T> *left;
TreeNode<T> *right;
TreeNode(T data) {
this->data = data;
left = NULL;
right = NULL;
}
};
************************************************************/
vector<int> levelOrder(TreeNode<int> * root){
// Write your code here.
vector<int> ans;
if(root==NULL){
return ans;
}
queue<TreeNode<int>*> q1;
q1.push(root);
while(!q1.empty()){
int size=q1.size();
for(int i=1;i<=size;i++){
TreeNode<int> * Node=q1.front();
q1.pop();
if(Node->left!=NULL) q1.push(Node->left);
if(Node->right!=NULL) q1.push(Node->right);
ans.push_back(Node->data);
}
}
return ans;
}