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

package container/list

MoveToBack moves element e (1st parameter) to the back of the given list. If e is not an element of the list, the list is not modified.

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

 package main

 import (
 "container/list"
 "fmt"
 )

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

  alist.MoveToBack(e)

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

 }

Output :

a

b

d

c <---- moved to the back of the list

Reference :

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

Advertisement