Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Function for Breadth-First Search in CPP
- // nodeptr = TreeNode*
- void bfs(nodeptr first) {
- queue <nodeptr> i;
- if (first != NULL)
- i.push(first);
- while (!i.empty()) {
- if (i.front()->left != NULL)
- i.push(i.front()->left);
- if (i.front()->right != NULL)
- i.push(i.front()->right);
- cout << i.front()->key << " ";
- i.pop();
- }
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment