You are viewing a single comment's thread. Return to all comments →
Wow I really need to work more Object-like... My solution works but is not be optimal... I like yours.
void LevelOrder(node * root){ static int depth = 1; static int level = 1; static bool next = false; if(level == depth){ cout << root->data << " "; } if((root->left || root->right || next) && level == depth) next = true; else next = false; ++depth; if(root->left && depth <= level) LevelOrder(root->left); if(root->right && depth <= level) LevelOrder(root->right); --depth; if(next && depth == 1){ ++level; next = false; LevelOrder(root); } }
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 →
Wow I really need to work more Object-like... My solution works but is not be optimal... I like yours.