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
+18.5k Golang : Aligning strings to right, left and center with fill example
+10.6k Golang : How to unmarshal JSON inner/nested value and assign to specific struct?
+11.9k Golang : Convert decimal number(integer) to IPv4 address
+29.5k Golang : Saving(serializing) and reading file with GOB
+7.5k Gogland : Single File versus Go Application Run Configurations
+13.1k Golang : Handle or parse date string with Z suffix(RFC3339) example
+8.3k Golang : Emulate NumPy way of creating matrix example
+17.2k Golang : Find file size(disk usage) with filepath.Walk
+6.8k Swift : substringWithRange() function example
+16k Golang : Read large file with bufio.Scanner cause token too long error
+6.2k Golang : Extract XML attribute data with attr field tag example
+5.8k Golang : List all packages and search for certain package