struct List
{
int data;
struct List *next;
};
struct tree *insertBST (struct tree *start, int data);
int main (int argc, char *argv[])
{
struct tree *start = NULL;
int num[] = {50, 68, 10};
for (int i = 0; i < 3; i++ )
start = insertBST (start, num[i]);
return 0;
}
struct tree *insertBST (struct tree *ptr, int data)
{
if (ptr == NULL)
{
ptr = (tree *)malloc (sizeof (tree *));
if (ptr == NULL)
printf ("Out of Space ************\n");
ptr->data = data;
ptr->left = NULL;
ptr->right = NULL;
}
else
{
if (data <= ptr->data)
ptr->left = insertBST (ptr->left, data );
else if(data > ptr->data)
ptr->right = insertBST (ptr->right, data);
}
return ptr;
}
|