Why is list pointer in struct Element of package list there?


(Pamleft) #1

I have read the list implement source code in Golang,and I don’t think the list pointer is necessary in struct Element of package list there?


(Jakob Borg) #2

I assume you mean container/list.Element. The list attribute is used in the methods on that type.


(Ali Koyuncu) #3

It is not necessary. But it adds more control on the doubly linked list implementations. One of advantages is stoping iteration when list is nil. Second if you would like to jump to root in some cases, you would need it. (not in golang list)