Recursive version of InsertNode -- Mine is called Enter Node
void EnterNode(TreePointer *node, int num)
{/* Enter an element into the tree */
/* pass in the address of the pointer to the current node */
TreePointer ptr;
ptr = *node;
if (!ptr) {
ptr = (TreePointer)malloc(sizeof(struct TreeNode));
ptr->data = num;
ptr->LeftChild = ptr->RightChild = NULL;
*node = ptr;
}
else if (num <= ptr->data)
EnterNode(&ptr->LeftChild, num);
else
EnterNode(&ptr->RightChild, num);
}
|