I have an ADT (PCB aka Process Control Block), I want to put them into a priority queue. How can I do it?
I already used How to put items into priority queues? to have a secondary priority to ensure the correct ordering of the queue. Here I can make the PCB comparable, but in another class, it may not make sense? In that case what might I do?
UPDATE
My code is very similar to that posted https://stackoverflow.com/a/9289760/292291
class PCB:
...
# in my class extending `PriorityQueue`
PriorityQueue.put(self, (priority, self.counter, pcb))
I think the problem is pcb is still not comparable here
OK just to close off this question. Heres what I did:
Make the ADT comparable: Implement
__lt__().This way, I can simply use
queue.put(obj)I found that @larsmans is right in saying