Using a container/heap to implement a priority queue

只谈情不闲聊 提交于 2019-12-04 09:34:33
package main
var PQ pqueue.PQueue
var firstNode pqueue.Node
PQ.Push(firstNode)

The variable firstNode is passed by value which means that there is an implicit assignment of the argument to the parameter in the function call PQ.Push(firstNode). The type pqueue.Node contains private fields such as row which are not exported from package pqueue to package main: "implicit assignment of unexported field 'row' of pqueue.Node in function argument."

In Node.go, add this function to package pqueue:

func NewNode() *Node {
    return &Node{}
}

In PQueue.go, add this function to package pqueue:

func NewPQueue() *PQueue {
    return &PQueue{}
}

Then. in package main, you can write:

PQ := pqueue.NewPQueue()
firstNode := pqueue.NewNode()
PQ.Push(firstNode)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!