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
+7.9k Golang : Grayscale Image
+6.8k Golang : Join lines with certain suffix symbol example
+9.7k Golang : Detect number of active displays and the display's resolution
+5.4k Golang : What is StructTag and how to get StructTag's value?
+14k Golang : Compress and decompress file with compress/flate example
+18.8k Golang : How to make function callback or pass value from function as parameter?
+15k Golang : How do I get the local IP (non-loopback) address ?
+7.5k Golang : Dealing with struct's private part
+19.6k Golang : Get current URL example
+5k Python : Convert(cast) bytes to string example
+5.8k Javascript : How to replace HTML inside <div>?
+6.8k Swift : substringWithRange() function example