定义队列为:
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
}
应该怎么解决?
还是不对呢
![52E)I$`T1(9]KV%{Q4OAIGY.png](https://static.studygolang.com/190329/1c854d87bc94cfd4492fe82bd08c059a.png)
#3
更多评论