March 2020
Intermediate to advanced
406 pages
8h 39m
English
A list is Go's implementation of a doubly linked list. This is built into the container/list package in the standard library. We can perform many actions using the implementation of a generic doubly linked list, as shown in the following code:
package mainimport ( "container/list" "fmt")func main() { ll := list.New() three := ll.PushBack(3) // stack representation -> [3] four := ll.InsertBefore(4, three) // stack representation -> [4 3] ll.InsertBefore(2, three) // stack representation -> // [4 2 3] ll.MoveToBack(four) // stack representation -> // [2 3 4] ll.PushFront(1) // stack representation -> // [1 2 3 4] listLength := ll.Len() fmt.Printf("ll type: %T\n", ll) fmt.Println("ll length: :", listLength) for e := ll.Front(); e != nil; ...Read now
Unlock full access