As suggested I start with linear search to make sure the bubble sort is working. When I test my code as mentioned with ./generate 1000 50 | ./find 127
, the result I have is:
haystack[0] = Retry:
Didn't find needle in haystack.
Please, help me what to do next. Is it my code that is not good or is there a step that I'm missing to do to link all the files?
Here's my code:
bool search(int value, int values[], int n)
{
// search by linear
for (int i = 0; i < n; i++)
{
if n < 0;
return false;
else
if (values[i] == value)
return true;
return false;
}
/**
* Sorts array of n values.
*/
void sort(int values[], int n)
{
// sort by bubble sort
for (int j = 0; j < n - 1; j++)
{
for (int k = 0; k < n - j - 1; k++)
if (values[k] > values[k + 1])
{
int temp = values[k];
values[k] = values[k + 1];
values[k + 1] = temp;
}
}
return;
}