Golang container/ring.Ring.Prev function example
package container/ring
Prev returns the previous ring element. The ring that is to be "Prev"ed must not be empty.
Golang container/ring.Ring.Prev function usage example
package main
import (
"container/ring"
"fmt"
)
func main() {
r := ring.New(10)
// populate our ring
for i := 10; i > 0; i-- {
r.Value = i
r = r.Prev() // Prev element to populate
}
fmt.Printf("%d ", r.Value)
reverse := r.Prev()
for ; reverse != r; reverse = reverse.Prev() {
fmt.Printf("%d ", reverse.Value)
}
fmt.Println()
}
Output :
10 9 8 7 6 5 4 3 2 1
Reference :
Advertisement
Something interesting
Tutorials
+29.5k Golang : How to create new XML file ?
+9.5k Mac OSX : Get a process/daemon status information
+11.6k Golang : Surveillance with web camera and OpenCV
+9.4k Golang : Terminate-stay-resident or daemonize your program?
+6.2k Linux/Unix : Commands that you need to be careful about
+15.6k Golang : rune literal not terminated error
+7.7k Gogland : Where to put source code files in package directory for rookie
+15.9k Golang : Get current time from the Internet time server(ntp) example
+5.6k Javascript : How to refresh page with JQuery ?
+46.5k Golang : Marshal and unmarshal json.RawMessage struct example
+14k Golang : Reverse IP address for reverse DNS lookup example
+14k Golang : Google Drive API upload and rename example