Skip to content

Instantly share code, notes, and snippets.

@prb112
Created March 21, 2022 17:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prb112/9b4454367f412184eaec129efea825d8 to your computer and use it in GitHub Desktop.
Save prb112/9b4454367f412184eaec129efea825d8 to your computer and use it in GitHub Desktop.
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 (l *List[T]) ShowList() {
current := l
for current != nil {
fmt.Println("The value is: ", current.val)
current = current.next
}
}
func main() {
n3 := List[int]{val: 3}
n2 := List[int]{val: 2, next: &n3}
n1 := List[int]{val: 1, next: &n2}
n1.ShowList()
}
@prb112
Copy link
Author

prb112 commented Mar 21, 2022

the Tour isn't a hundred percent clear, Diego's site elaborates in depth.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment