insertNode(struct node* n, int x)
{
if(n != NULL)
{
n = (struct node*) malloc(sizeof(struct node));
n->number = x;
n->left = NULL;
n->right = NULL;
}
else if(n->number > x)
insertNode(n->left, x);
else
insertNode(n->right, x);
}
The compiler doesn't complain, but I always get a segmentation fault, so instead, I have to rely on pointers to pointers. It seems a bit strange, Can anyone explain why?
This post has been edited by SilverMage: 08 October 2012 - 05:54 AM

New Topic/Question
Reply




MultiQuote






|