문제

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.

enter image description here

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top