Last active
September 20, 2015 05:35
-
-
Save ahmedahamid/4d058cbaf948a8c05a80 to your computer and use it in GitHub Desktop.
Tricky pointer basics explained | Iterative implementation of binary search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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