-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroundrobin.cpp
More file actions
65 lines (59 loc) · 1.36 KB
/
Copy pathroundrobin.cpp
File metadata and controls
65 lines (59 loc) · 1.36 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,t,time=0;
cout<<"Enter number of processes ";
cin>>n;
vector<int> bt(n),p(n),
ct(n),tat(n),wt(n),rem(n),btc(n);
for(int i=0;i<n;i++){
cout<<"enter burst time of process "<<i+1<<" ";
cin>>bt[i];
rem[i]=bt[i];
btc[i]=bt[i];
p[i]=i;
}
wt[0]=0;
cout<<"Enter time quantum: ";
cin>>t;
while(true){
bool isdone=true;
for(int i=0;i<n;i++){
if(rem[i]>0) {
isdone=false;
if(rem[i]>t){
time+=t;
rem[i]-=t;
}
else {
time+=rem[i];
wt[i]=time-bt[i];
rem[i]=0;
}
}
}
if(isdone) break;
}
ct[0]=bt[0];
tat[0]=ct[0];
for(int i=1;i<n;i++){
wt[i]=wt[i-1] + btc[i-1];
ct[i]=btc[i]+wt[i];
tat[i]=ct[i]-p[i];
}
cout<<"waiting time: ";
for(int i=0;i<n; i++){
cout <<wt[i]<<" ";
}
cout<<endl;
cout<<"turn around time: ";
for(int i=0;i<n; i++){
cout <<tat[i]<<" ";
}
cout<<endl;
cout<<"complete time: ";
for(int i=0;i<n; i++){
cout <<ct[i]<<" ";
}
cout<<endl;
}