-1
I am having doubts in this code of the function of inserting circular list.
tipo_lista * inserir_inicio (tipo_lista * p, tipo_lista * novo_no)
{
//Se a lista estiver vazia
if(p==NULL)
return novo_no;
tipo_lista* r = p; //Para manter a referencia ao primeiro elemento
while (p->prox != NULL)
{
p = p->prox;
}
p->prox = novo_no;
return r;
}
It’s not working properly and I’m wondering if it’s on that line of NULL
.
This list is not circular. A circular list has no end; let’s say the last element points to the first, not null
– Jefferson Quesado
Do you talk about a double-linked or circular list? If it is actually circular, the while is an infinite loop, because there will always be a next. On this site ( >https://www.tutorialspoint.com/data_structures_algorithms/circular_linked_list_algorithm.htm ), a circular list is defined as having a head, which makes it possible to insert it at the beginning. In the link there is an example of insertion.
– Filipe Olegario
You say:
novo -> prox = novo;
?– André
@Filipeolegario circular only.
– André
@Lucastrigueiro please give an answer on this. I am not able to function the list on, nor print, nor insert, based on the
main
that you had done, only missing those two functions.– André
First need to know in which position you are trying to insert, start? order? ordered?
– Lucas Trigueiro
insert normally start, 1,2,3
– André