Last active
March 15, 2021 19:30
-
-
Save mlcollard/a2111503d37b6c54d4f217c49f49ad94 to your computer and use it in GitHub Desktop.
This file contains 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
int position(int key, int elemArray[]) { | |
int bottom = 0; | |
int top = elemArray.length - 1; | |
while (bottom <= top) { | |
int midpoint = (top + bottom) / 2; | |
// found it | |
if (key == elemArray[midpoint]) | |
return midpoint; | |
// top half | |
if (key < elemArray[midpoint]) | |
bottom = midpoint + 1; | |
// bottom half | |
else | |
top = midpoint - 1; | |
} | |
// not in the array | |
return -1; | |
} |
This file contains 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
int position(int key, int elemArray[]); |
This file contains 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
void sort(double n[], int size); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment