Skip to content

Commit

Permalink
level order display-bfs
Browse files Browse the repository at this point in the history
  • Loading branch information
WaderManasi committed Sep 8, 2020
1 parent ea5098d commit 212343d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Tree/LevelOrder_Display.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//Given a binary tree, find its level order traversal.
//Level order traversal of a tree is breadth-first traversal for the tree.

vector<int> levelOrder(Node* root)
{
vector<int>v;
if(root==NULL) return v;

queue<Node*>q;
q.push(root);

while(!q.empty())
{
Node* temp=q.front();
v.push_back(temp->data);
q.pop();
if(temp->left!=NULL) q.push(temp->left);
if(temp->right!=NULL) q.push(temp->right);

}
return v;
}

0 comments on commit 212343d

Please sign in to comment.