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
+41k Golang : How to check if a string contains another sub-string?
+15.8k Golang : Get digits from integer before and after given position example
+8.6k Golang : Convert(cast) []byte to io.Reader type
+6.3k Unix/Linux : Use netstat to find out IP addresses served by your website server
+6.7k Golang : Skip or discard items of non-interest when iterating example
+14.4k Golang : On enumeration
+32.7k Golang : Regular Expression for alphanumeric and underscore
+7.9k Golang : How to feed or take banana with Gorilla Web Toolkit Session package
+9.6k Golang : Read file with ioutil
+15.2k JavaScript/JQuery : Detect or intercept enter key pressed example
+6.9k Golang : Fibonacci number generator examples