Golang container/list.List.InsertBefore() function example
package container/list
InsertBefore inserts a new element with given value immediately before mark and returns the new element. If mark is not an element of the list, the list is not modified.
Golang container/list.List.InsertBefore() function usage example
package main
import (
"container/list"
"fmt"
)
func main() {
alist := list.New()
insertelem := alist.PushFront("a")
alist.PushFront("c")
alist.InsertBefore("b",insertelem)
for e := alist.Front(); e != nil; e = e.Next() {
fmt.Println(e.Value) // print out the elements
}
}
Output :
c
b
a
Reference :
Advertisement
Something interesting
Tutorials
+14.3k Golang : How to shuffle elements in array or slice?
+7.2k Golang : Null and nil value
+5.8k Golang : List all packages and search for certain package
+15.6k Golang : Convert date format and separator yyyy-mm-dd to dd-mm-yyyy
+18k Golang : Get all upper case or lower case characters from string example
+15k Golang : How do I get the local IP (non-loopback) address ?
+15.6k Chrome : ERR_INSECURE_RESPONSE and allow Chrome browser to load insecure content
+20.9k PHP : Convert(cast) int to double/float
+14.4k Golang : Find network of an IP address
+16.6k Golang : Merge video(OpenCV) and audio(PortAudio) into a mp4 file
+5.8k Unix/Linux : Get reboot history or check when was the last reboot date