|
The program enters integers one by one. When the input integer is not the end flag -9999, it is inserted into the binary sorting tree. If the value node is found to exist in the binary sorting tree during the insertion process, the repeatability is counted The count of this node. Until the end of all input.
#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);
}
} |
|