Skip to content

Instantly share code, notes, and snippets.

@ahmedahamid
Last active September 20, 2015 06:20
Show Gist options
  • Save ahmedahamid/f7525863e3f5acdca659 to your computer and use it in GitHub Desktop.
Save ahmedahamid/f7525863e3f5acdca659 to your computer and use it in GitHub Desktop.
Tricky pointer basics explained | Recursive implementation of insertion into binary search tree
tree_node* insert(tree_node* n, int value)
{
if (n == NULL)
{
tree_node* new_node = new tree_node();
new_node->data = value;
new_node->left = new_node->right = NULL;
return new_node;
}
if (value == n->data)
{
return n;
}
if (value < n->data)
{
n->left = insert(n->left, value);
}
else
{
n->right = insert(n->right, value);
}
return n;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment