I only heard about linked lists a couple weeks ago, and now I'm into circular linked lists. The question is simple: In a circular list that only has one element, is the next node himself, i.e. does it link back to himself or to null? Because if I try to add a new element in the next node position I will also be overwriting the present node (the first if the list has only one element and it links back to himself).
Thank you.
In a circular list that only has one element, is the next node himself, i.e. does it link back to himself or to null?
The next node is himself, not NULL
.
if I try to add a new element in the next node position I will also be overwriting the present node...
If it currently only has one node, to add a new node, it is equivalent to add the note to its end.
New->next = Cur; // same as: New->next = Rear->next;
Prev->next = New; // same as: Rear->next = New;
Rear = New;
Check out this presentation for more details.