27 lines
493 B
Go
27 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() ...
|
||
|
}
|