Day 23: BST Level-Order Traversal

  • + 0 comments
    void levelOrder(Node * root){
     vector<Node*> oQ;
     
     if (nullptr != root) {
      oQ.push_back(root);
    
      for(int i=0; i<oQ.size(); i++) {
       cout<<oQ[i]->data<<" ";
    
       if (nullptr != oQ[i]->left)
        oQ.push_back(oQ[i]->left);
    
       if (nullptr != oQ[i]->right)
        oQ.push_back(oQ[i]->right);
      }
     }
    }