Skip to content

Instantly share code, notes, and snippets.

@ahmedahamid
Last active September 20, 2015 05:35
Show Gist options
  • Save ahmedahamid/4d058cbaf948a8c05a80 to your computer and use it in GitHub Desktop.
Save ahmedahamid/4d058cbaf948a8c05a80 to your computer and use it in GitHub Desktop.
Tricky pointer basics explained | Iterative implementation of binary search
tree_node* binary_search(tree_node* n, int value)
{
if (n == NULL)
{
return NULL;
}
tree_node* x = n;
while (x != NULL)
{
if (value == x->data)
{
return x;
}
if (value < x->data)
{
x = x->left;
}
else
{
x = x->right;
}
}
return NULL; // value was not found
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment