gfg right view of tree
C++
/* 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; // distance from parent node. distance of root node will be 0.
Obj(Node *node, int dist)
{
root = node;
dis = dist;
}
};
// function to print right view.
void rightView(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;
}
Also in C++:
- Title
- set in c++
- Category
- C++
- Title
- c++ sql
- Category
- C++
- Title
- console colors in C++
- Category
- C++
- Title
- E/flutter (20384): [ERROR:flutter/third_party/txt/src/minikin/FontFamily.cpp(184)] Could not get cmap table size! E/flutter (20384): F/flutter (20384): [FATAL:flutter/third_party/txt/src/minikin/FontCollection.cpp(95)] nTypefaces == 0
- Category
- C++
- Title
- differentialble programming
- Category
- C++
- Title
- pair in c++
- Category
- C++
- Title
- passing a vector to a function c++
- Category
- C++
- Title
- c++ reset stream
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- convert stirng to int c++
- Category
- C++
- Title
- first prime numbers
- Category
- C++
- Title
- c++ overloaded == operator
- Category
- C++
- Title
- trovare il valore massimo in un array c++ w3
- Category
- C++
- Title
- *min_element in c++
- Category
- C++
- Title
- How to read a file in in C++
- Category
- C++
- Title
- single line if c++
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- shuffle vector c++
- Category
- C++
- Title
- clear file before writing c++
- Category
- C++
- Title
- how to compare lower case character to uppercase cpp
- Category
- C++
- Title
- worker class c++
- Category
- C++
- Title
- type id c++
- Category
- C++
- Title
- how to pass an object by reference in c++
- Category
- C++
- Title
- c++ cli convert string to string^
- Category
- C++
- Title
- how to include seld declared header file in c++
- Category
- C++
- Title
- length of string in c++
- Category
- C++
- Title
- is x prime?
- Category
- C++
- Title
- lambda operator in c++
- Category
- C++
- Title
- solve linear equations geeksforgeeks
- Category
- C++
- Title
- how to check type in c++
- Category
- C++
- Title
- c++ replace substrings
- Category
- C++
- Title
- switch statement c++
- Category
- C++
- Title
- double pointers C++
- Category
- C++
- Title
- friend function in c++
- Category
- C++
- Title
- zeros of array c++
- Category
- C++
- Title
- how to round to nearest whole number unity
- Category
- C++
- Title
- c++ convert const char* to LPCWSTR
- Category
- C++
- Title
- c++ variable argument
- Category
- C++
- Title
- loop through array c++
- Category
- C++
- Title
- how to remove maximum number of characters in c++ cin,ignore
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- cpp create lambda with recursion
- Category
- C++
- Title
- system("pause") note working c++
- Category
- C++
- Title
- vector initialization c++
- Category
- C++
- Title
- c++ do while loop
- Category
- C++
- Title
- string input
- Category
- C++
- Title
- map vs unordered_map in C++
- Category
- C++
- Title
- c++ loop trhought object
- Category
- C++
- Title
- retu7rn this c++
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++
- Title
- flushing output in c++
- Category
- C++
- Title
- min heap priority queue c++
- Category
- C++
- Title
- what is difference between ciel and floor
- Category
- C++
- Title
- new in c++
- Category
- C++
- Title
- runtime error in c++
- Category
- C++
- Title
- two sum problem in c++
- Category
- C++
- Title
- string comparison in c++
- Category
- C++
- Title
- hobo 8
- Category
- C++
- Title
- how to iterate through a map in c++
- Category
- C++
- Title
- screen record ios simulator
- Category
- C++
- Title
- capitalize first letter c++
- Category
- C++
- Title
- c++ not greater than
- Category
- C++
- Title
- quick sort predefined function in c++
- Category
- C++
- Title
- c++ dereference a pointer
- Category
- C++
- Title
- accumulate in cpp
- Category
- C++
- Title
- c++ char print align
- Category
- C++
- Title
- namespaces c++
- Category
- C++
- Title
- how to convert int to string c++
- Category
- C++
- Title
- new keyword in cpp
- Category
- C++
- Title
- how to get last element of set in c++
- Category
- C++
- Title
- How to find the suarray with maximum sum using divide and conquer
- Category
- C++
- Title
- Find the duplicate in an array of N integers.
- Category
- C++
- Title
- how to print eachh chars in string data type in c++
- Category
- C++
- Title
- c++ wait for user input
- Category
- C++
- Title
- tuple c++
- Category
- C++
- Title
- how to iterate through array in c++
- Category
- C++
- Title
- fail() in c++
- Category
- C++
- Title
- Convert binary tree to a doubly linked list
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- how print fload wiht 3 decimal in c++
- Category
- C++
- Title
- c++ class constructor
- Category
- C++
- Title
- how to create object in c++
- Category
- C++
- Title
- building native binary with il2cpp unity
- Category
- C++
- Title
- prefix sum array
- Category
- C++
- Title
- min and max heap in cpp
- Category
- C++
- Title
- Check if a Number is Odd or Even using Bitwise Operators
- Category
- C++
- Title
- matrix transpose tiling
- Category
- C++
- Title
- random number generator c++
- Category
- C++
- Title
- c++ program for matrix addition
- Category
- C++
- Title
- Insert into vector C++
- Category
- C++
- Title
- const in c++
- Category
- C++
- Title
- function template
- Category
- C++
- Title
- array 2d to 1d
- Category
- C++
- Title
- hashmap in c++
- Category
- C++
- Title
- pass ss tream as parameter c++
- Category
- C++
- Title
- C++ Student::Student()
- Category
- C++
- Title
- sqrt cpp
- Category
- C++
- Title
- initialize int c++
- Category
- C++
- Title
- regexp_like oracle c++
- Category
- C++
- Title
- subarray sum in c++
- Category
- C++