排序二叉树:
(1).每个节点中包含有一个关键值 (2).任意一个节点的左子树(如果存在的话)的关键值小于该节点的关键值 (3).任意一个节点的右子树(如果存在的话)的关键值大于该节点的关键值。
左边的节点全部大于右边的节点。
建立排序二叉树;
输入一组数据,将该组数据建立排序二叉树。
struct node *creat(struct node *root, int x)
{
if(root == NULL)
{
root = (struct node *)malloc(sizeof(struct node));
root->ltree = NULL;
root->rtree = NULL;
root->data = x;
}
else
{
if(x>root->data)
{
root->rtree = creat(root->rtree, x);
}
else
{
root->ltree = creat(root->ltree, x);
}
}
return root;
};