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
+10.3k Golang : How to check if a website is served via HTTPS
+12k Golang : Clean formatting/indenting or pretty print JSON result
+8.6k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+11.7k Golang : Calculations using complex numbers example
+8.9k Golang : GMail API create and send draft with simple upload attachment example
+15.2k Golang : Get timezone offset from date or timestamp
+5.9k Golang : Denco multiplexer example
+11.6k Get form post value in Go
+10.6k Golang : How to delete element(data) from map ?
+37.5k Upload multiple files with Go
+7.5k Golang : How to handle file size larger than available memory panic issue
+28.8k Golang : Detect (OS) Operating System