摘要:
http://www.geeksforgeeks.org/lowest-common-ancestor-binary-tree-set-1/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11 struct node {12 int data;13 struct node *left, *right;14 node() : data(0), left(NULL), right(... 阅读全文
摘要:
http://www.geeksforgeeks.org/print-ancestors-of-a-given-binary-tree-node-without-recursion/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11 struct node {12 int data;13 struct node *left, *right;14 node() : data(0... 阅读全文
摘要:
http://www.geeksforgeeks.org/in-place-convert-a-given-binary-tree-to-doubly-linked-list/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11 struct node {12 int data;13 struct node *left, *right;14 node() : data(0), ... 阅读全文
摘要:
http://www.geeksforgeeks.org/iterative-postorder-traversal-using-stack/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11 struct node {12 int data;13 struct node *left, *right;14 node() : data(0), left(NULL), right... 阅读全文
摘要:
http://www.geeksforgeeks.org/largest-independent-set-problem/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11 struct node {12 int data;13 struct node *left, *right;14 node() : data(0), left(NULL), right(NULL) { }... 阅读全文
摘要:
http://www.geeksforgeeks.org/morris-traversal-for-preorder/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11 struct node {12 int data;13 struct node *left, *right;14 node() : data(0), left(NULL), right(NULL) { }15... 阅读全文
摘要:
http://www.geeksforgeeks.org/full-and-complete-binary-tree-from-given-preorder-and-postorder-traversals/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11 struct node {12 int data;13 struct node *left, *right;14 no... 阅读全文
摘要:
http://www.geeksforgeeks.org/boundary-traversal-of-binary-tree/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 #include 9 using namespace std;10 11 struct node {12 int data;13 struct node *left, *right;14 node() : data(0), left(NULL), right(NULL) {... 阅读全文
摘要:
http://www.geeksforgeeks.org/convert-a-given-tree-to-sum-tree/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 10 struct node {11 int data;12 struct node *left, *right;13 node() : data(0), left(NULL), right(NULL) { }14 node... 阅读全文
摘要:
http://www.geeksforgeeks.org/populate-inorder-successor-for-all-nodes/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 10 struct node {11 int data;12 struct node *left, *right, *next;13 node() : data(0), left(NULL), right(NULL)... 阅读全文
摘要:
http://www.geeksforgeeks.org/connect-nodes-at-same-level-with-o1-extra-space/recursive: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 10 struct node {11 int data;12 struct node *left, *right, *next;13 node() : data(0), left(N... 阅读全文
摘要:
http://www.geeksforgeeks.org/check-if-a-given-binary-tree-is-sumtree/ 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 using namespace std; 9 10 struct node {11 int data;12 struct node *left, *right;13 node() : data(0), left(NULL), right(NULL) { }14 ... 阅读全文