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.2k Golang : Delete certain files in a directory
+8.1k Golang : Detect number of active displays and the display's resolution
+31.3k Golang : Smarter Error Handling with strings.Contains()
+11.3k Golang : Sort and reverse sort a slice of bytes
+6.7k Golang : Grayscale Image
+3.7k Mac OSX : Get disk partitions' size, type and name
+10.5k Linux : How to install driver for 600Mbps Dual Band Wifi USB Adapter
+12.1k Golang : Generate Code128 barcode
+16.5k Golang : Put UTF8 text on OpenCV video capture image frame
+5.6k Golang : How to setup a disk space used monitoring service with Telegram bot