-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnon preemptive priority
68 lines (59 loc) · 1.17 KB
/
non preemptive priority
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
66
67
68
#include <iostream>
#include <algorithm>
using namespace std;
typedef struct proccess
{
int at,bt,pr,ct,ta,wt;
string pro_id;
}process;
bool compare(process a,process b)
{
return a.at<b.at;
}
bool compare2(process a,process b)
{
return a.pr>b.pr;
}
int main()
{
process pro[10];
int n,i,j;
cout<<"Enter the number of process::";
cin>>n;
cout<<"Enter the process id arrival time burst time and priority :::";
for(i=0;i<n;i++)
{
cin>>pro[i].pro_id;
cin>>pro[i].at;
cin>>pro[i].bt;
cin>>pro[i].pr;
}
sort(pro,pro+n,compare);
pro[0].ct=pro[0].bt+pro[0].at;
pro[0].ta=pro[0].ct-pro[0].at;
pro[0].wt=pro[0].ta-pro[0].bt;
i=1;
while(i<n-1)
{
for(j=i;j<n;j++)
{
if(pro[j].at>pro[i-1].ct)
break;
}
sort(pro+i,pro+i+(j-i),compare2);
pro[i].ct=pro[i-1].ct+pro[i].bt;
pro[i].ta=pro[i].ct-pro[i].at;
pro[i].wt=pro[i].ta-pro[i].bt;
i++;
}
pro[i].ct=pro[i-1].ct+pro[i].bt;
pro[i].ta=pro[i].ct-pro[i].at;
pro[i].wt=pro[i].ta-pro[i].bt;
for(i=0;i<n;i++)
{
//desplaying all the values
cout<<pro[i].pro_id<<"\t"<<pro[i].at<<"\t"<<pro[i].bt<<"\t"<<pro[i].ct<<"\t"<<pro[i].ta<<"\t"<<pro[i].wt<<"\t"<<pro[i].pr;
cout<<endl;
}
return 0;
}