Originally Posted by
anduril462
I find the "GAP" version stupid. It uses unnecessary paramaters and variables that just confuse things.
That's what I am saying!
I think something like this should work:
Code:
int fun(Treeptr p, int * ap, int * bp) {
int a, b;
if (p->left == NULL && p->right == NULL) {
*ap = p->value;
return 1;
}
if (p->right == NULL) {
*bp = p->value;
return (fun(p->left, &b, ap) && p->value > b);
}
if (p->left == NULL) {
*ap = p->value;
return (fun(p->right, &a, bp) && p->value < a);
}
return (fun(p->right, &a, bp) && fun(p->left, &b, ap));
}
However, the code I provided above for the treemanagement.c seems to fail to build a BST, or maybe the printing is not accurate, so I am testing it further in paper. Thanks anduril462.
If someone can verify that the above is correct or not, (s)he is welcomed.
[EDIT]
It appears that the printing was done horizontally and not vertically. So I could test the function and it seems OK.