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

package container/list

PushBackList inserts a copy of an other list at the back of the given list . The lists and other may be the same.

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

 package main

 import (
 "container/list"
 "fmt"
 )

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


  blist := list.New()
  blist.PushBack("d")
  blist.PushBack("e")
  blist.PushBack("f")

  alist.PushBackList(blist)

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

 }

Output :

a

b

c

d

e

f

Reference :

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

Advertisement