So I've been struggling with this for some time now and now I feel I'm totally stuck. I'm done with selection sort and binary search in helpers.c, and I think they are working all right. Actually for some time they almost used to, the program did find the bloody needle but it didn't say anything when the needle was not in the haystack, so I fiddled around with it, and now it just doesn't do anything anymore. It compiles, it lists the pseudo-random haystack items and bamm, nothing. Only ctrl+c helps. Same in gdb, when I give the input manually, doesn't do anything for ctrl+d. For check50 it says "unexpected end of input". I'm really, really lost and have no idea how to proceed. Please help :) And here's the code itself:
bool search(int value, int values[], int n)
{
if (n < 0)
{
return 1;
}
while (n >= 0)
{
int start = 0;
int finish = n-1;
int mid = (start + finish)/2;
if (values[mid] == value)
return true;
else if (values[mid] < value)
// if value is higher than mid, search right
{
start = mid + 1;
bool search(int value, int values[], int n);
}
else if (values[mid] > value)
// if value is lower than mid, search left
{
finish = mid - 1;
bool search(int value, int values[], int n);
}
}
return false; }
And this is the sorting thingy:
void sort(int values[], int n) {
for (int i = 1; i < n; i++)
{
int element = values[i];
int j = i;
while (j > 0 && element < values[j-1])
{
values[j] = values [j-1];
j = j-1;
values[j] = element;
}
}
return;