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

package container/list

PushFront inserts a new element e with value at the front of list l and returns the new element.

 package main

 import (
 "container/list"
 "fmt"
 )

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

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

 }

Output :

d

c

b

a

Reference :

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

Advertisement