• + 0 comments
            if(subroot==NULL) return;
            if(a[x].first==0 || a[x].second>deep) 
                a[x]={subroot->data,deep};
            NLR(deep+1,subroot->left,a,x-1);
            NLR(deep+1,subroot->right,a,x+1);
        }
        void topView(Node * root) {
            if(root==NULL) return;
            map<int,pair<int,int>> res;
            int x=0;
            int deep=0;
            res[x]={root->data,deep};
            NLR(deep+1,root->left,res,x-1);
            NLR(deep+1,root->right,res,x+1);
            for(auto i:res){
                cout<<i.second.first<<" ";
            }
        }