数据结构:
typedef struct node
{
struct node *left;
struct node *right;
int data;
}node_type;
三目运算 + 递归:
boolean is_bst(struct node *root)
{
return root==NULL?TRUE:(root->left==NULL?(root->left->data < root->data && is_bst(root->left) && is_bst(root->right)):(root->right==NULL?TRUE:(root->data < root->right->data && is_bst(root->right))));
}
what? 核心代码只有一行?! ——嗯!
(转发请注明出处)