我有一个ADT(PCB aka Process Control Block),我想把它们放到一个优先级队列中。我该怎么做?
我已经使用How to put items into priority queues?来获得第二优先级,以确保队列的正确顺序。在这里我可以使PCB具有可比性,但在另一个类中,它可能没有意义?那样的话我该怎么办?
更新
我的代码与发布的https://stackoverflow.com/a/9289760/292291非常相似
class PCB:
...
# in my class extending `PriorityQueue`
PriorityQueue.put(self, (priority, self.counter, pcb))
我认为问题是pcb在这里还是不可比的
好吧,结束这个问题。以下是我所做的:
使ADT具有可比性:实现
__lt__()
。这样,我可以简单地使用
queue.put(obj)
我发现拉斯曼说得对
相关问题 更多 >
编程相关推荐