/**
* helpers.c
*
* Computer Science 50
* Problem Set 3
*
*/
#include <cs50.h>
#include <math.h>
#include "helpers.h"
/**
* Returns true if value is in array of n values, else false.
*/
//Recursive Search
bool bsearch(int key, int array[], int min, int max)
{
int mid1 = 0;
int mid = 0;
if(max < min)
{
return false;
}
else
{
mid1 = max / 2;
mid = round(mid1);
if(array[mid] < key)
{
return bsearch(key, array, mid + 1, max);
}
else if(array[mid] < key)
{
return bsearch(key, array, min, mid - 1);
}
else
{
return true;
}
}
}
/**
* Returns true if value is in array of n values, else false.
*/
bool search(int value, int values[], int n)
{
bsearch(value, values, values[0], n);
}
/**
* Sorts array of n values.
*/
void sort(int values[], int n)
{
int j = 0;
int k = n;
for(int i = 0; i < n; i++)
{
if(values[i] == 0)
{
}
else if(values[i] < j)
{
j = values[i];
values[k] = j;
k = k - 1;
}
[mod: snipped code as not necessary to answer question.]