Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 5
- 3 10
- 1 1
- 4 2
- 5 1
- 2 5
- */
- /*
- Enter The process Number
- 4
- Enter The priority Number and burst time
- 3 20
- 2 5
- 10 7
- 4 15
- Top value pq: 2-> Position : 2-> Start time : 0 -> Finish time : 5
- Top value pq: 3-> Position : 1-> Start time : 5 -> Finish time : 25
- Top value pq: 4-> Position : 4-> Start time : 25 -> Finish time : 40
- Top value pq: 10-> Position : 3-> Start time : 40 -> Finish time : 47
- Avg Waiting time : 17.5
- Avg Turn around time : 29.25
- Throughput : 0.034188
- */
- #include<bits/stdc++.h>
- using namespace std;
- priority_queue <pair<int,pair<int,int > > >pq;
- int main()
- {
- int num,bt,prior,waiting=0,turnaround=0;
- cout<<"Enter The process Number "<<endl;
- cin>>num;
- cout<<"Enter The priority Number and burst time "<<endl;
- int ans[num+10],totaltime=0,sumtime=0;
- for (int i=0; i<num; i++)
- {
- cin>>prior>>bt;
- pq.push(make_pair(-1*prior,make_pair(bt,i))) ;
- }
- while(!pq.empty())
- {
- pair<int,pair<int,int> >t=pq.top();
- int pos=t.second.second;
- totaltime=t.second.first;
- cout<<"Top value pq: "<<-1*t.first<<"-> Position : "<<pos+1<<"-> Start time : "<<sumtime<<" ";
- waiting=waiting+sumtime;
- sumtime=sumtime+totaltime;
- cout<<"-> Finish time : "<<sumtime<<endl;
- turnaround=turnaround+sumtime;
- pq.pop();
- }
- cout<<"Avg Waiting time : "<<1.0* waiting/num<<endl;
- cout<<"Avg Turn around time : "<<1.0*turnaround/num<<endl;
- cout<<"Throughput : "<<1.0*num/turnaround<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement