定义队列为:
type Type interface {}
type Queue struct {
items []Type
lock sync.Mutex
}
func (queue *Queue) New() *Queue {
queue.items=[]Type{}
return queue
}
//入队列
func (queue *Queue) EnQueue(item Type) {
queue.lock.Lock()
queue.items=append(queue.items,item)
queue.lock.Unlock()
}
//出队列
func (queue *Queue) DeQueue() *Type {
queue.lock.Lock()
item := queue.items[0]
queue.items=queue.items[1:]
queue.lock.Unlock()
return &item
}
定义的树结构为:
type Type interface {}
type Tree struct {
value Type
left *Tree
right *Tree
}
func (tree *Tree) InitTree(num []int,root *Tree) {
var que queue.Queue
quee := que.New()
node := root
node.value=num[0]
node.left=nil
node.right=nil
quee.EnQueue(node)
var tmp *Tree
tmp=quee.DeQueue() //出现错误,*Type 不能赋值给 *Tree
}
应该怎么解决?
更多评论