forked from HemangTheHuman/hacktoberfest-2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshortest_job_first_scheduling.cpp
More file actions
59 lines (58 loc) · 1.1 KB
/
shortest_job_first_scheduling.cpp
File metadata and controls
59 lines (58 loc) · 1.1 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
#include<iostream>
using namespace std;
int main()
{
int n,i,j;
cout<<"Enter the number of processes: ";
cin>>n;
int bt[n],p[n],wt[n],tt[n],pr[n];
cout<<"Enter the burst time of each process: ";
for (i=0;i<n;i++)
{
cin>>bt[i];
}
for(i=0;i<n;i++)
{
p[i]=i;
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(bt[i]>bt[j])
{
swap(bt[i],bt[j]);
swap(p[i],p[j]);
}
}
}
wt[0]=0;
cout<<"Waiting time of each process is: ";
for(i=1;i<n;i++)
{
wt[i]=wt[(i-1)]+bt[(i-1)];
}
for(i=0;i<n;i++)
{
cout<<"\nwt["<<i<<"] :"<<wt[i];
}
for(i=0;i<n;i++)
{
tt[i]=wt[i]+bt[i];
}
for(i=0;i<n;i++)
{
cout<<"\ntt["<<i<<"] :"<<tt[i];
}
float avgwt=0,avgtt=0;
for(i=0;i<n;i++)
{
avgwt=avgwt+wt[i];
avgtt=avgtt+tt[i];
}
avgwt=avgwt/n;
avgtt=avgtt/n;
cout<<"\n\n Average waiting time: "<<avgwt;
cout<<"\n Average turn around time: "<<avgtt;
return 0;
}