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
+15.4k Golang : invalid character ',' looking for beginning of value
+6.9k Default cipher that OpenSSL used to encrypt a PEM file
+15.6k Golang : How to convert(cast) IP address to string?
+46.4k Golang : Encode image to base64 example
+25.4k Golang : Convert long hexadecimal with strconv.ParseUint example
+11k Golang : Create S3 bucket with official aws-sdk-go package
+13.7k Golang : Tutorial on loading GOB and PEM files
+20.9k Golang : Convert PNG transparent background image to JPG or JPEG image
+5.3k Swift : Convert string array to array example
+10k Golang : Convert octal value to string to deal with leading zero problem
+18.4k Golang : Read binary file into memory
+12.8k Golang : Convert int(year) to time.Time type