2
This code below does not work properly, I type 5 knots and was to return the number 5 (total amount of knots entered). It happens that returns me 4.
int qtd_no_lista (tipo_lista * recebida)
{
tipo_lista * aux = recebida;
int cont=0;
while (aux -> prox != NULL)
{
aux = aux ->prox;
cont++;
}
printf("A quantidade de nos presente na lista e %d\n",cont);
return cont;
}
I think the mistake is on the line of while
, I’m not sure.
It’s decreasing, I think when I point to the next one it automatically decreases in total.
So it’s always going to be like this: is Prox going to have NULL value? Talking about this code there, because this is wrong. Loop stops in NULL and is not counted at the end?
– André
'Cause you’re telling me to do it. There’s nothing wrong, it’s just math.
– Maniero
I managed to return the correct quantity here, removed the '-> Prox' and compiled return correctly now.
– André
It is a solution, I only have my doubts if you will always do everything you want. I can’t even say because I don’t know what you want.
– Maniero