Write C code to check if a given binary tree is a binary search tree or not?

October 28, 2007 · Filed Under Placement Questions, Tree 



Don't want to miss a single bit? Subscribe By Email for Daily Jobs

Enter your email address :

All the latest from JobsAdda on Jobsadda.com delivered to your mailbox everyday.

Here is a C program which checks if a given tree is a Binary Search Tree or not…

int isThisABST(struct node* mynode)
{
if (mynode==NULL) return(true);
if (node->left!=NULL && maxValue(mynode->left) > mynode->data)
return(false);
if (node->right!=NULL && minValue(mynode->right) <= mynode->data)
return(false);
if (!isThisABST(node->left) || !isThisABST(node->right))
return(false);

return(true);
}

Related Articles


Get Latest JobsAdda.com Jobs, news & updates  via Email