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

package container/list

MoveAfter moves an element (1st parameter) to its new position after mark (2nd parameter) in the list. If the element or mark is not an element of the list, or e == mark, the list is not modified.

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

 package main

 import (
 "container/list"
 "fmt"
 )

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

  e := alist.PushBack("d")

  alist.MoveAfter(e, mark)

  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.MoveAfter

Advertisement