![image.png](https://static.studygolang.com/181214/80d0d9079d253a93f15541f4dab0f168.png)
package main
import (
"container/list"
"container/ring"
"fmt"
)
func main() {
list := list.New()
list.PushBack(1)
list.PushBack(2)
list.PushBack(3)
fmt.Printf("first: %#v\n",list.Front())
fmt.Printf("second: %#v\n",list.Front().Next())
fmt.Printf("len:%v\n",list.Len())
//初始化环
ring :=ring.New(3)
for i :=1; i <= 3; i++{
ring.Value = i
ring = ring.Next()
}
//计算1+2+3
s := 0
//ring 遍历
ring.Do(func(p interface{}){
s += p.(int)
})
fmt.Println("sum is",s)
}
END.
有疑问加站长微信联系(非本文作者)