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

package container/list

InsertAfter inserts a new element with given value immediately after mark and returns the new element. If mark is not an element of the list, the list is not modified.

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

 package main

  import (
 "container/list"
 "fmt"
  )

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

 alist.InsertAfter("b",insertelem)

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

Output :

a

b

c

Reference :

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

Advertisement