I have just started Pset3. I was going well untilluntil as per specification I read this "Re-write search in such a way that it uses linear search, returning true if value is in values and false if value is not in values. Take care to return false right away if n isn’t even positive." I
Re-write search in such a way that it uses linear search, returning
true
ifvalue
is invalues
andfalse
ifvalue
is not invalues
. Take care to returnfalse
right away ifn
isn’t even positive.
I was like what am I suppose to do now? Still having no idea what to do I wrote this code in search function in helpers.c
bool search(int value, int values[], int n) { if (n < 0) { return false; }helpers.c
for (int i = 0 ; i < n; i++)
{
if (values[i] == value)
{
return true;
}
else
return false;
}
}
bool search(int value, int values[], int n)
{
if (n < 0)
{
return false;
}
for (int i = 0 ; i < n; i++)
{
if (values[i] == value)
{
return true;
}
else
{
return false;
}
}
}
But didnt gotdidn't get the needle, so the question here is? what am i supposeI supposed to do here? amAm i going in the right direction? anyAny help or hint would really be appreciated.