Is there a way to mimic creating multiple queues like this but with priority queue?

This is what i have but i want to now use a priority queue.

queue<PCB> Disks[DiskDevices];

I tried this but it doesnt work.

priority_queue<PCB> DisksTest[DiskDevices];

It wont compile? What am i doing wrong?

3 Years
Discussion Span
Last Post by mystycs

Could you post the full error message you are getting, please? (The compiler and OS you are using would help as well.)

If you could also give more information about your goals, it would help greatly in assessing your real needs. When you say that an array of queues doesn't work, can you explain why it doesn't? Why do you think you want an array of priority queues instead? What does the PCB class represent? Is DiskDevices constant? If not, could you use a vector or other type of container of the priority_queues, like so:

std::vector <std::priority_queue<PCB> > DiskTest[DiskDevices];

(Note that I used explicit scoping on the STL types; I recommend doing that rather than using namespace std;, as it gives better control over the namespace. Since it doesn't seem to have had any impact on using std::queue<>, I doubt it is the cause of the problem, but it certainly couldn't hurt anythin except your fingers.)


Mind you, despite the name, a priority queue is nothing like a FIFO queue in its behavior; it rather is a heap which keeps the objects it contains in a particular order. If the class being contained does not have an implicit ordering, this may be the cause of the problem, in which case you would need to define both the underlying container type, and a comparator function, like so:

std::vector <std::priority_queue<PCB, std::vector<PCB>, PcbComparator> > DiskTest[DiskDevices];

...where PcbComparator() is a bool function that compares the values of two PCB objects and returns true if they are in the specified order and false if not. If this isn't the behavior you want, then a priority queue isn't the right container type.

Edited by Schol-R-LEA

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.