Seg Fault in BST Insertion

When I call the following binary search tree insert function with the function call
insert(root, "apple"), the compiler seg faults. Is there an explanation?

struct node
{
string data;
node* left;
node* right;
};


void insert(node* &root, string add_me)
{
if (root == NULL)
{
root -> data = add_me;
root -> left = NULL;
root -> right = NULL;
}
else if (add_me <= root -> data)
{

insert(root->left, add_me);
}
else
{
insert(root->right, add_me);
}
}
You're purposely dereferencing a NULL pointer...
I got it. I forgot to allocate dynamic memory.
Topic archived. No new replies allowed.