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

package container/list

MoveAfter moves an element (1st parameter) to its new position before 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.MoveBefore() 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.MoveBefore(e, mark)

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

 }

Output :

a

b

d

c

Reference :

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

Advertisement