Problem1765--是否二叉搜索树

1765: 是否二叉搜索树

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 0  Solved: 0
[Submit] [Status] [Web Board] [Creator:]

Description

本题要求实现函数,判断给定二叉树是否二叉搜索树。 函数接口定义: bool IsBST ( BinTree T ); 其中BinTree结构定义如下: typedef struct TNode *Position; typedef Position BinTree; struct TNode{ ElementType Data; BinTree Left; BinTree Right; }; 函数IsBST须判断给定的T是否二叉搜索树,即满足如下定义的二叉树: 定义:一个二叉搜索树是一棵二叉树,它可以为空。如果不为空,它将满足以下性质: 非空左子树的所有键值小于其根结点的键值。 非空右子树的所有键值大于其根结点的键值。 左、右子树都是二叉搜索树。 如果T是二叉搜索树,则函数返回true,否则返回false。 裁判测试程序样例: #include #include typedef enum { false, true } bool; typedef int ElementType; typedef struct TNode *Position; typedef Position BinTree; struct TNode{ ElementType Data; BinTree Left; BinTree Right; }; BinTree BuildTree();

Input

二叉树T

Output

如果T是二叉搜索树,则函数返回true,否则返回false

Sample Input Copy

图1

Sample Output Copy

Yes

Source/Category

70