You are viewing a single comment's thread. Return to all comments →
Simple with a queue
#include <queue> void LevelOrder(node * root) { queue<node*> nodes; if (root) nodes.push(root); for (; !nodes.empty(); nodes.pop()) { cout<<nodes.front()->data<<' '; if (nodes.front()->left) nodes.push(nodes.front()->left); if (nodes.front()->right) nodes.push(nodes.front()->right); } }
Seems like cookies are disabled on this browser, please enable them to open this website
Tree: Level Order Traversal
You are viewing a single comment's thread. Return to all comments →
Simple with a queue