Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
isBST
//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) {} }; bool isBST(BinTree *cur) { bool left_ok = true; bool right_ok = true; if (cur->left) if (cur->left->data >= cur->data) return false; else left_ok = isBST(cur->left); if (cur->right) if (cur->right->data <= cur->data) return false; else right_ok = isBST(cur->right); return (left_ok && right_ok); } 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); */ BinTree *d = new BinTree(5, NULL, NULL); BinTree *c = new BinTree(6, d, NULL); BinTree *b = new BinTree(2, NULL, NULL); BinTree *a = new BinTree(4, b, c); cout << isBST(a); }
run
|
edit
|
history
|
help
0
Problema2
at_multimap_example
Merge intervals leetcode
XD
Org
informatika / Cinta Avrille X MIPA 5
Web Browser History - SET
ledproject
HeapSort
Area of a triangle using templete