Skip to content

Instantly share code, notes, and snippets.

@misterpoloy
Created August 18, 2020 04:39
Show Gist options
  • Save misterpoloy/92145f95cdaccfc3c475012bba83b474 to your computer and use it in GitHub Desktop.
Save misterpoloy/92145f95cdaccfc3c475012bba83b474 to your computer and use it in GitHub Desktop.
Breadth First Traversal
void traverseLevelOrder() {
if (head == nullptr) return;
std::cout << "-- LEVEL ORDER TRAVERSE" << std::endl;
std::queue<BSTNode*> queue;
queue.push(head);
while (!queue.empty()) {
BSTNode* current = queue.front();
std::cout << queue.front()->value << std::endl;
if (current->left != nullptr) queue.push(current->left);
if (current->right != nullptr) queue.push(current->right);
queue.pop();
}
};
@misterpoloy
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment