• + 1 comment
    void topView(Node * root) {
    
        vector<int> vL, vR;
        Node *t = root;
    
        while(t){
    
            t = t->left;
            if(t) vL.push_back(t->data);
        }
    
        t = root;
    
        while(t){
    
            vR.push_back(t->data);
            t = t->right;
        }
    
        for(int i=vL.size()-1; i>=0; i--) cout<<vL[i]<<" ";
        for(int i=0; i<vR.size(); i++) cout<<vR[i]<<" ";
    
    }
    
    
    
        Can anyone explain why this code doesn't work?