Microsoft Interview Question

check if a BT is BST

Interview Answer

Anonymous

Jul 21, 2013

// Check if a BT is BST bool IsBST(TreeNode* const root) { if (!root) return true; bool ell = (root->left ? root->left->data data : true); bool are = (root->right ? root->right->data >= root->data : true); return ell && are && IsBST(root->left) && IsBST(root->right); }