当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


GO Ring.Prev用法及代码示例


GO语言"container/ring"包中"Ring.Prev"类型的用法及代码示例。

用法:

func(r *Ring) Prev() *Ring

Prev 返回前一个环元素。 r 不能为空。

例子:

package main

import (
	"container/ring"
	"fmt"
)

func main() {
	// Create a new ring of size 5
	r := ring.New(5)

	// Get the length of the ring
	n := r.Len()

	// Initialize the ring with some integer values
	for i := 0; i < n; i++ {
		r.Value = i
		r = r.Next()
	}

	// Iterate through the ring backwards and print its contents
	for j := 0; j < n; j++ {
		r = r.Prev()
		fmt.Println(r.Value)
	}

}

输出:

4
3
2
1
0

相关用法


注:本文由纯净天空筛选整理自golang.google.cn大神的英文原创作品 Ring.Prev。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。