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
+25.6k Golang : convert rune to integer value
+13.5k Golang : Read XML elements data with xml.CharData example
+10.4k Golang : Meaning of omitempty in struct's field tag
+6.2k Golang & Javascript : How to save cropped image to file on server
+8.6k Android Studio : Import third-party library or package into Gradle Scripts
+6.1k Golang : How to write backslash in string?
+6k Golang : Experimenting with the Rejang script
+6k Javascript : Get operating system and browser information
+5.5k Golang : Display advertisement images or strings on random order
+31.6k Golang : Get local IP and MAC address
+7.1k Nginx : How to block user agent ?