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

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?

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

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)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.