Tree: Level Order Traversal

  • + 0 comments

    My C++ Implementation

    queue<Node*> Q;
        Q.push(root);
    
        while (!Q.empty()) {
    
    
                Node *current = Q.front();
    
               cout<<current->data<<" ";
    
                if(current->left != nullptr)
                {
                    Q.push(current->left);
                }
                if(current->right != nullptr)
                {
                    Q.push(current->right);
                }
                Q.pop();
    
        }