Im getting the wrong output. In my while loop for the else statement I want it to perform the subtraction operation and then put that data on the queue pq2. I put a cout statement to make sure that the data is on the pq2 queue. However Im getting weird numbers.
This is my output:
PID: 3 Initial Priority: 32 Service Time: 0.52
Process is done
PID: 45 Initial Priority: 12 Service Time: 1.1
Process is done
PID: 0 Initial Priority: 1 Service Time: 5.51
Changed Quantum: 1.01
PID: -1073741821Priority: -1073741821 Changed Service Time: 2.8026e-45
PID: 1 Initial Priority: 1 Service Time: 6
Changed Quantum: 1.5
PID: -1073741821Priority: -1073741821 Changed Service Time: 2.8026e-45
The output should be:
PID: 3 Initial Priority: 32 Service Time: 0.52
Process is done
PID: 45 Initial Priority: 12 Service Time: 1.1
Process is done
PID: 0 Initial Priority: 1 Service Time: 5.51
Changed Quantum: 1.01
PID: 0 Priority: 1 Changed Service Time: 1.01
PID: 1 Initial Priority: 1 Service Time: 6
Changed Quantum: 1.5
PID: 1 Priority: 1 Changed Service Time: 1.5
This is what I have for my main:
int main(){
priority_queue<Event, vector<Event>, ComparePriority> pq;
float quantum = 4.5;
Event events[4]= { {0, 1, 5.51}, {1, 1, 6.00}, {45, 12, 1.10}, {3, 32, 0.52}};
for (int i = 0; i < 4; ++i)
pq.push(events[i]);
while (! pq.empty()) {
Event events2=pq.top();
cout<<"PID: "<<events2.pid<<" Initial Priority: "<<events2.priority<<" Service Time: "<<events2.service<<endl;
if (events2.service<quantum){
cout<<"Process is done"<<endl;
//pq.pop();
}else{
events2.service-=quantum;
cout<<"Changed Quantum: "<<events2.service<<endl;
priority_queue<Event, vector<Event>, ComparePriority> pq2;
Event events2=pq2.top();
cout<<"PID: "<<events2.pid<<"Priority: "<<events2.priority<<" Changed Service Time: "<<events2.service<<endl;
//cout<<"PID: "<<events2.pid<<" Initial Priority: "<<events2.priority<<" Service Time: "<<events2.service<<endl;
//put at the end of the line to go back through the loop next cycle
}
pq.pop();
}
return 0;
}