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
+12.1k Golang : Split strings into command line arguments
+6.5k Grep : How to grep for strings inside binary data
+11.6k Get form post value in Go
+10k Golang : Setting variable value with ldflags
+18.5k Golang : Write file with io.WriteString
+8.3k Golang : Count leading or ending zeros(any item of interest) example
+5.9k Golang : Denco multiplexer example
+23.2k Golang : Print out struct values in string format
+19.3k Golang : Get host name or domain name from IP address
+6.9k Nginx : Password protect a directory/folder
+9.2k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+6k Golang : Convert Chinese UTF8 characters to Pin Yin