Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Blog
Right view of a tree
//Title of this code #include <iostream> #include <list> using namespace std; struct BinTree { int data; BinTree *left; BinTree *right; BinTree(int d, BinTree* l, BinTree* r): data(d), left(l), right(r) {} }; static int max_height; void left_tree_view(BinTree* cur, int height) { if (!cur) return; if (height > max_height) { cout << cur->data << endl; ++max_height; } left_tree_view(cur->right, height + 1); left_tree_view(cur->left, height + 1); } int main() { BinTree *j = new BinTree(9, NULL, NULL); BinTree *h = new BinTree(8, NULL, NULL); BinTree *g = new BinTree(7, NULL, NULL); BinTree *f = new BinTree(6, h, j); BinTree *e = new BinTree(5, NULL, NULL); BinTree *d = new BinTree(4, NULL, NULL); BinTree *c = new BinTree(3, f, g); BinTree *b = new BinTree(2, d, e); BinTree *a = new BinTree(1, b, c); max_height = 0; left_tree_view(a, 1); }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
Beadandó
TraceMarrix
triplets from vector
Rotate array
c++_array_size
СПКИ АП КЭП 3
Dar
nani
quickselect
Networked path_dp
stackse - search stackoverflow differently
Please log in to post a comment.