0
Personal I am with a doubt of where and how I should change to this function of printing circular list get correct.
Below is a print function from a linked list:
void imprime_lista(tipo_lista* p)
{
while (p != NULL)
{
printf("%d\n", p->info);
p = p -> prox;
}
printf("\n");
}
It worked, but gave the message of the program stopped working, in
main
I’m calling forimprime_lista(p);
– André
You might want to check before you enter
do {} while
ifprimeiro
is notNULL
and put(p && p != primeiro)
as a stop criterion; thus, ifp
is empty or is not a truth circular list, the function is not lost.– Wtrmute
If you pass an empty list the program will give error even. I added an if to fix it. Another thing that might be causing the error is that a list that is not circular has been passed.
– Lucas Trigueiro
Still the same thing
– André
Probably your circular list is wrong at some point
– Lucas Trigueiro
Take a look please: https://pastebin.com/9VKC7uBK
– André
The insert function is wrong, it is inserting as a simple list and not as circular, so after the last element the list goes to NULL and is where the error happens.
– Lucas Trigueiro
@Lucigueiro I changed the insert function, the current code is like this: [coddigocomplete]: https://pastebin.com/GBd9xjCH Now I do not know where the error is happening if it is in the print or insert function. If you run nothing comes out on the screen. Thanks.
– André
The error is in the inserts because you check if it is null and returns and as the list starts in null the program will never get out of it.
– Lucas Trigueiro