How to Use container/list (Doubly Linked List) in Go

Create a doubly linked list in Go using the container/list package to efficiently add, remove, and iterate over elements.

Use the container/list package to create a doubly linked list by calling list.New() and manipulating elements with methods like PushBack, Front, and Next.

package main

import (
	"container/list"
	"fmt"
)

func main() {
	l := list.New()
	l.PushBack(1)
	l.PushBack(2)
	l.PushBack(3)

	for e := l.Front(); e != nil; e = e.Next() {
		fmt.Println(e.Value)
	}
}