Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
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
top5words
Dar
TypeSizeTest
Suma
QP
C++ Solar eclipse program(Shoushi integrated) 1644 - 1785 from Ideone( Date: August 14, 2014 )
CPP - Pointers - Ex.3
odws
Korelacja Pearsona lol
GL interview