"gfg bottom view of tree" Code Answer's

You're definitely familiar with the best coding language C++ that developers use to develop their projects and they get all their queries like "gfg bottom view of tree" answered properly. Developers are finding an appropriate answer about gfg bottom view of tree related to the C++ coding language. By visiting this online portal developers get answers concerning C++ codes question like gfg bottom view of tree. Enter your desired code related query in the search bar and get every piece of information about C++ code related question on gfg bottom view of tree. 

gfg bottom view of tree

By Rid09Rid09 on Jun 08, 2020
/* This is not the entire code. It's just the function which implements 
   bottom view. You need to write required code. */

// Obj class is used to store node with it's distance from parent.
class Obj
{
    public:
        Node *root;
        int dis;

        Obj(Node *node, int dist)
        {
            root = node;
            dis = dist;
        }
};

// bottom view logic below.
void bottomView(Node *root)
{
    queue<Obj*> q;
    q.push(new Obj(root, 0));
    map<int,int> m;

    while(!q.empty())
    {
        Obj *ob = q.front();
        q.pop();

        m[ob->dis] = ob->root->data;

        if(ob->root->left != NULL)
            q.push(new Obj(ob->root->left, ob->dis-1)); 
        if(ob->root->right != NULL)
            q.push(new Obj(ob->root->right, ob->dis+1));
    }

    for(auto it=m.begin(); it!=m.end(); it++)
        cout << it->second << "\t";

    cout << endl;
}

Add Comment

2

All those coders who are working on the C++ based application and are stuck on gfg bottom view of tree can get a collection of related answers to their query. Programmers need to enter their query on gfg bottom view of tree related to C++ code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about gfg bottom view of tree for the programmers working on C++ code while coding their module. Coders are also allowed to rectify already present answers of gfg bottom view of tree while working on the C++ language code. Developers can add up suggestions if they deem fit any other answer relating to "gfg bottom view of tree". Visit this developer's friendly online web community, CodeProZone, and get your queries like gfg bottom view of tree resolved professionally and stay updated to the latest C++ updates. 

C++ answers related to "gfg bottom view of tree"

View All C++ queries

C++ queries related to "gfg bottom view of tree"

Browse Other Code Languages

CodeProZone