Skip to content

Instantly share code, notes, and snippets.

@amigo421
Created January 24, 2020 12:42
Show Gist options
  • Save amigo421/ffe41869bfd2589157d5852f8fc52eca to your computer and use it in GitHub Desktop.
Save amigo421/ffe41869bfd2589157d5852f8fc52eca to your computer and use it in GitHub Desktop.
BFS
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