forked from dharmanshu1921/Daa-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstComeFirstServe Algo.cpp
More file actions
51 lines (46 loc) · 971 Bytes
/
FirstComeFirstServe Algo.cpp
File metadata and controls
51 lines (46 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<bits/stdc++.h>
using namespace std;
int main()
{
vector<pair<int,int> >v;
int n;
cout<<"enter the no of process";
cin>>n;
int att,btt;
for(int i=1;i<=n;i++)
{
cout<<"enter the process"<<i<<" arrival time and burst time\n";
cin>>att>>btt;
v.push_back({att,btt});
}
sort(v.begin(),v.end());
int ct=0;
ct=v[0].first;
vector<pair<int,int> >temp;
for(int i=0;i<=n;i++)
{
if(ct<v[i].first)
ct=ct+v[i].first;
temp.push_back({ct,ct+v[i].second});
ct=ct+v[i].second;
}
int tt[n]={0};
int wt=0;
for(int i=0;i<n;i++){
tt[i]+=temp[i].second-v[i].first;
wt+=tt[i]-v[i].second;
}
cout<<"\naverage waiting time\n"<<wt/n;
int sum=0;
for(int i=0;i<n;i++)
{
sum+=tt[i];
}
int st=0;
for(int i=0;i<n;i++)
{
st+=temp[i].first-v[i].first;
}
cout<<"\navg tt time\n"<<sum/n;
cout<<"\n response time is \n"<<st/n;
}