Q1.
NODE* head //points to the bst(if it exists)
void exist_bst(NODE *tree)
{
if(tree != NULL)
{
if(tree->left->info < tree->info && tree->right->info >= tree->info)
{
if(check(tree))
head = tree;
}
else
{
exist_bst(tree->left);
exist_bst(tree->right);
}
}
}
int check(NODE *root)
{
if(root->left == NULL && root->right == NULL)
return TRUE;
if(tree->left->info >= tree->info || tree->right->info < tree->info)
return FALSE;
else return (check(tree->left) || check(tree->right));
}
I havn't run this on system and this code is subject to more optimisation.
This was just to give you a fair idea
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/algogeeks/-/0YV_4hilHhkJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.