Beyond the error: unknown type name 'bool' | has some other minor function errors
while (aux -> prox != NULL)
You will not check the last item in the list.
else {
return false;
}
The else
is not necessary, to return false
if the list has been traversed and the value not found, just put the return after while
.
bool tem_numero_na_lista(tipo_lista * aux, int valor) {
while (aux != NULL) {
if (aux -> info == valor) {
return true;
}
aux = aux -> prox;
}
return false;
}
Already having lista
with values entered, you can test like this:
Ex: Verify that the number 7 is in the list.
int valor = 7;
if( tem_numero_na_lista(lista, valor) )
printf("Encontrou o valor %d na lista", valor);
else
printf("Não encontrou o valor %d na lista", valor);