im working on a program and what i have to do is pass in process time of jobs into a priority queue processing min time jobs first. there is also a high priority job which should stop everything and be processed right away which is the 30 with priority 1 job. im stuck on how to do this i have my jobs being created and their processing times done. i am trying to make a function where i would pass thoe processing times in along with priority to put them into the queue to be processed but i have no idea how to implement this. this is my code so far creating all the jobs and process times. ive never used priority queues or heaps and i tried googling it to learn but i just dont understand if any1 can exaplin what to do or how i can achieve this that would be great.
@dhayden
i was trying to do that but it didnt work with me i was just trying to store it in a regular queue and that wasnt really working when im trying to print it out
In your example, myqueue is a local variable and you are either adding something to it (lines 9-10) or printing it out (line 14) but not both, so you're guaranteed to print an empty queue only.
Your priority queue must be part of the class or passed into pass2queue by reference etc. Also, what's in the priority queue probably has to be a class containing the process priority, remaining process runtime, maybe process id. You might call it class Process :). Add an operator <() to sort the Jobs by priority.
As dhayden suggested, you can modify the STL priority queue. You can declare a modified priority queue like: priority_queue<Job, vector<Job>, "Some comparative here"> myQueue;
This means that the priority queue is filled with a class Job, which can have your different times and priority in it; it uses a vector for queue storage, and the last one is the comparing method on how to sort things within the queue.
You can make your own operator overload class function to tell the queue how you want things sorted. Since you said by processing times, you can make a class function that overloads () and takes in two types of jobs, compares their processing time, and return true/false if one job is lower processing time than the other.
@danghotties
so like when you delcare all those things inside the priority queue and class it will automatically run those each time some thing is put into it automatically storing it??