Skip to content

Instantly share code, notes, and snippets.

@jotaki
Last active December 24, 2015 17:59
Show Gist options
  • Save jotaki/6840066 to your computer and use it in GitHub Desktop.
Save jotaki/6840066 to your computer and use it in GitHub Desktop.
struct node_s * add_node(struct node_s ** tree, struct node_s * leaf)
{
if(*tree == NULL)
*tree = leaf;
else if((*tree)->key > leaf->key) {
leaf->right = *tree;
*tree = leaf;
}
else if((*tree)->key < leaf->key) {
leaf->left = *tree;
*tree = leaf;
}
else { // ==
free(*tree);
*tree = leaf;
}
return leaf;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment