Golang container/list.List.PushBack() function example

package container/list

PushBack inserts a new element e with value at the back of list l and returns the new element.

Golang container/list.List.PushBack() function usage example

 package main

 import (
 "container/list"
 "fmt"
 )

 func main() {
  alist := list.New()
  alist.PushBack("a")
  alist.PushBack("b")
  alist.PushBack("c")
  alist.PushBack("d")

  for e := alist.Front(); e != nil; e = e.Next() {
 fmt.Println(e.Value) // print out the elements
  }

 }

Output :

a

b

c

d

Reference :

http://golang.org/pkg/container/list/#List.PushBack

Advertisement