Created
May 24, 2018 01:49
-
-
Save reyou/0668356a5234085c160378ffdcb6bc12 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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