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

package container/list

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

Golang container/list.List.PushFrontList() 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.PushFrontList(blist)

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

 }

Output :

d

e

f

a

b

c

Reference :

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

Advertisement