在Go中,我如何迭代指针列表?

时间:2014-05-17 05:05:34

标签: go

我想迭代这个:

*list.List

我该怎么做?

func Foo(key string, values *list.List) string {
...

//I want to iterate and get value from "values"
}

这个Foo被这样调用:

kvs := make(map[string]*list.List)
res := Foo(k, kvs[k]) //k is string

谢谢!

1 个答案:

答案 0 :(得分:5)

查看示例@ http://golang.org/pkg/container/list/

func Foo(key string, vl *list.List) string {
    for e := l.Front(); e != nil; e = e.Next() {
        v := e.Value
    }
    return ""
}

//编辑:检查Create a Golang map of Lists