Created
July 16, 2017 23:32
-
-
Save bernar83/ffe70d99a9741172ef67aab27e8c9d50 to your computer and use it in GitHub Desktop.
Need help pointing out what's wrong with my code for cs50's pset3's find
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
bool search(int value, int values[], int n) | |
{ | |
int start = 0; | |
int end = n - 1; | |
while (start <= end) | |
{ | |
int mid = (start + end) / 2; | |
if (values[mid] == value) | |
{ | |
return true; | |
} | |
else if (values[mid] > value) | |
{ | |
end = mid - 1; | |
} | |
else | |
{ | |
start = mid + 1; | |
} | |
} | |
return false; | |
} | |
/** | |
* Sorts array of n values. | |
*/ | |
void sort(int values[], int n) | |
{ | |
// sort the array | |
for (int i = 0; i < (n - 1); i++) | |
{ | |
int min = values[i]; | |
for (int j = 0; j < n; j++) | |
{ | |
if (min > values[j]) | |
{ | |
min = values[j]; | |
values[j] = values[i]; | |
values[i] = min; | |
} | |
} | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment