Skip to content

Instantly share code, notes, and snippets.

@reyou
Created May 24, 2018 01:49
Show Gist options
  • Save reyou/0668356a5234085c160378ffdcb6bc12 to your computer and use it in GitHub Desktop.
Save reyou/0668356a5234085c160378ffdcb6bc12 to your computer and use it in GitHub Desktop.
// https://www.youtube.com/watch?v=86g8jAQug04
#include <iostream>
#include <queue>
using namespace std;
struct Node
{
char data;
Node *left;
Node *right;
} void LevelOrder(Node *root)
{
if (root == NULL)
return;
queue<Node *> Q;
Q.push(root);
while (!Q.empty())
{
Node *current = Q.front();
cout << current->data << " ";
if (current->left != NULL)
{
Q.push(current->left);
}
if (current->right != NULL)
{
Q.push(current->right);
}
// removing the element at front
Q.pop();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment