Skip to content

Instantly share code, notes, and snippets.

@bernar83
Created July 16, 2017 23:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bernar83/ffe70d99a9741172ef67aab27e8c9d50 to your computer and use it in GitHub Desktop.
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
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