Generic data structures

Go uses maps, slices, and the container package for data structures, allowing custom generic types via type parameters.

Go does not have a single built-in 'generic data structure' type; instead, it uses the map type for key-value storage and slice for dynamic arrays, while the container package provides specialized structures like heap and ring. For type-safe generic collections, you define your own using type parameters (e.g., type List[T any] struct { ... }) or use the container/list package for linked lists.

package main

import (
	"fmt"
	"container/list"
)

func main() {
	// Generic map
	m := make(map[string]int)
	m["apple"] = 1

	// Generic slice
	s := []int{1, 2, 3}

	// Linked list (type-safe via interface or explicit type)
	l := list.New()
	l.PushBack("hello")
	fmt.Println(m, s, l.Back().Value)
}