Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Left 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->left, height + 1); left_tree_view(cur->right, height + 1); } // 1 // / \ // 2 3 // / \ / \ // 4 5 6 7 // / \ // 8 9 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
Cotton Farm 0.0.1.0
fcyyfc
threadpool02
LIS
Updated Linked Lists - 5/10/2017 V4.0
template
Kishan_Basic_Geometry
CPP - Arrays - Ex.2 - Solution
Adress
variadic template