-
Notifications
You must be signed in to change notification settings - Fork 0
/
SmallestJobFirst.cpp
43 lines (41 loc) · 979 Bytes
/
SmallestJobFirst.cpp
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
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cout<<"Enter the number of process"<<endl;
cin>>n;
pair<int,int>time[n];
int ct[n];
int bt_[n];
pair<int,int> bt[n];
int curr=0;
cout<<"Enter the bust time of the process"<<endl;
for(int i=0;i<n;i++){
cin>>bt[i].first;
bt_[i]=bt[i].first;
bt[i].second=i;
}
sort(bt,bt+n);
for(int i=0;i<n;i++){
ct[bt[i].second]=curr+bt[i].first;
curr+=bt[i].first;
}
// for(int i=0;i<n;i++){
// tat[i]=ct[i]-bt_[i];
// }
float avgTat=0;
for(int i=0;i<n;i++){
avgTat+=ct[i];
}
cout<<"Turnaround Time of the process is as follows: "<<"\n";
for(int i=0;i<n;i++){
cout<<ct[i]<<" ";
}
cout<<endl;
cout<<"Waiting Time of the process is as follows: "<<"\n";
for(int i=0;i<n;i++){
cout<<ct[i]-bt_[i]<<" ";
}
avgTat/=n;
cout<<"\n"<<avgTat<<endl;
}