I'm trying to implement a linked list with a generic data type and I created a method new() which creates a list with a nil root and length = 0. Now the problem is how do I initialize the list in the main function.
type Node[T any] struct {
data T
next *Node[T]
}
type LinkedList[T any] struct {
root *Node[T]
length uint
}
func (list *LinkedList[T]) new() *LinkedList[T] {
return &LinkedList[T]{root: nil, length: 0}
}
func main() {
list := LinkedList[int].new()
}
This is what I tried to do which gives "cannot call pointer method new on LinkedList[int]".