I haven't seen your code that calls insert
, but I'm going to guess that it looks something like:
node_ptr tree = NULL;
insert("abcd", tree);
insert("123", tree);
insert("xyz", tree);
The problem is that tree
never gets updated to point to the correct node in the calling function.
If you change it to:
node_ptr tree = NULL;
tree = insert("abcd", tree);
insert("123", tree);
insert("xyz", tree);
it should work.