We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
voidlevelOrder(Node*root){queue<Node*>q;if(root==NULL)return;q.push(root);// add root to queuewhile(!q.empty()){for(inti=0;i<q.size();i++){Node*tempN=q.front();cout<<tempN->data<<" ";// if you want to store you can do push_back hereq.pop();if(tempN->left!=NULL)q.push(tempN->left);if(tempN->right!=NULL)q.push(tempN->right);}}}
Cookie support is required to access HackerRank
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 →
My C++ Solution: