Created
January 24, 2020 12:42
-
-
Save amigo421/ffe41869bfd2589157d5852f8fc52eca to your computer and use it in GitHub Desktop.
BFS
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
struct node { | |
int data; | |
node *left = nullptr; | |
node *right = nullptr; | |
}; | |
void TraversBFS(node *root) { | |
std::queue<node *> q; | |
q.push(root); | |
for (node *n = q.front(); !q.empty(); n = q.front()) { | |
q.pop(); | |
// visit( n ); | |
if (n->left) | |
q.push(n->left); | |
if (n->right) | |
q.push(n->right); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment