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 |
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
- Write C code to return a pointer to the nth node of an inorder traversal of a BST.
- Write a C program to create a mirror copy of a tree (left nodes become right and right nodes become left)!
- Write a C program to find the mininum value in a binary search tree.
- Write a C program to find the mininum value in a binary search tree.
- Write a C program to find the depth or height of a tree.


