Skip to content

Commit

Permalink
Create LevelOrder Traversal.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Mugdha-Hazra authored Nov 23, 2021
1 parent 7f0ff29 commit c299e5e
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions LevelOrder Traversal.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Complete the levelOrderTraversal function below.
/* For your reference:
struct node
{
ll value;
node *left;
node *right;
};
*/

void levelOrderTraversal(node *root)
{ queue<node *>q;
q.push(root);
while(!q.empty())
{
auto temp=q.front();
q.pop();
cout<<temp->value<<" ";
if(temp->left!=NULL)
q.push(temp->left);
if(temp->right!=NULL)
q.push(temp->right);
}

}

0 comments on commit c299e5e

Please sign in to comment.