【发布时间】:2014-01-12 05:12:25
【问题描述】:
http://play.golang.org/p/icQO_bAZNE
我正在练习使用堆排序,但是
prog.go:85: type bucket is not an expression
prog.go:105: cannot use heap.Pop(bucket[i].([]IntArr)) (type interface {}) as type int in assignment: need type assertion
[process exited with non-zero status]
我遇到了这些错误,不知道如何正确键入 assert
问题出在以下几行:
heap.Push(bucket[x].([]IntArr), elem)
arr[index] = heap.Pop(bucket[i].([]IntArr))
因为我想使用堆结构来从每个桶中提取值
每个桶都是[]IntArr
而IntArr 是[]int,如下所示
type IntArr []int
type bucket [10]IntArr
周末尝试了很多方法,还是搞不定,非常感谢。
【问题讨论】:
标签: types interface go type-conversion