Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Created May 10, 2016 00:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/a3194f885fc542a7f5827cbcdc92a3f5 to your computer and use it in GitHub Desktop.
Save jianminchen/a3194f885fc542a7f5827cbcdc92a3f5 to your computer and use it in GitHub Desktop.
HackerRank - Tree - Level Order Traversal
/*
struct node
{
int data;
node* left;
node* right;
}*/
#include <queue>
using namespace std;
void LevelOrder(node * root)
{
if(root==NULL)
return;
queue<node*> myQueue ;
myQueue.push(root);
while(!myQueue.empty())
{
node* cur = myQueue.front();
myQueue.pop();
printf("%d ", cur->data);
if(cur->left!=NULL)
myQueue.push(cur->left);
if(cur->right!=NULL)
myQueue.push(cur->right);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment