go-learning/4generics/generic-types.go
2023-08-25 19:09:21 +03:00

26 lines
493 B
Go

package main
import "fmt"
// List represents a singly-linked list that holds
// values of any type.
type List[T any] struct {
next *List[T]
val T
}
func main() {
list := List[any]{}
list.next = &List[any]{}
list.val = 123
list.next.val = "hello"
fmt.Println(list.val)
fmt.Println(list.next.val)
fmt.Println(list)
// NEXT complete linked list implementation
// single linked list
// doubly linked list
// addNode(), addNodeAt(), deleteNode(), deleteNodeAt(), getList() ...
}