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

package container/list

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

Golang container/list.List.MoveToFront() 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.MoveToFront(e)

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

 }

Output :

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

a

b

d

Reference :

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

Advertisement