|
程序逐个输入整数,当输入的整数不是结尾标志-9999时,将其插入到二叉排序树中.若在插入过程中发现该值结点二叉排序树中已经存在,则将重复度计入该结点的count记数中.直到全部输入结束.
#include<stdio.h>
#include<stdlib.h>
typedef struct Binary
{
int val,count;
struct Binary *left *right;
}Binary;
void binaryTree( Binary **t, int data)
{
Binary *ptr,*p;
int d;
p=NULL;
ptr=_______(1)_______;
while(_______(2)_______)
{
if(data == ptr->val)
_______(3)_______;
else
{
p=ptr;
ptr=_______(4)_______;
}
ptr = (Binary *)malloc(sizeof(Binary));
ptr->right = ptr->left = NULL;
_______(5)_______;
if(_______(6)_______)
_______(7)_______ = ptr;
else if(data > p->val)
p->right = ptr;
else
p->left = ptr;
}
void main()
{
Binary *root=NULL;
int d;
scanf("%d",&d);
while(d!=-9999)
{
binaryTree(_______(8)_______);
scanf("%d",&d);
}
} |
|