When you don't have brackets with a while, if, else, etc, then only one statement is part of that loop or block. So
Code:
while (here->data != target && here->link != NULL)
here = here->link;
is the same as
Code:
while (here->data != target && here->link != NULL)
{
here = here->link;
}
The same is true for the if and the else. Here is the same code with brackets added and indentation fixed to make it more readable:
Code:
bool search(NodePtr head, int target)
{
NodePtr here = head;
if (here == NULL)
{
return false;
}
else
{
while (here->data != target && here->link != NULL)
{
here = here->link;
}
if (here->data == target)
{
return true;
}
else
{
return false;
}
}
}