-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfcfs_without_arrival.cpp
More file actions
42 lines (33 loc) · 881 Bytes
/
fcfs_without_arrival.cpp
File metadata and controls
42 lines (33 loc) · 881 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
#include <bits/stdc++.h>
using namespace std;
struct Process {
int id, bt, wt, tat;
};
void printSequence(const vector<int>& seq) {
cout << "Job Sequence: ";
for (int i = 0; i < seq.size(); i++) {
cout << "P" << seq[i];
if (i != seq.size()-1) cout << " -> ";
}
cout << "\n\n";
}
int main() {
int n;
cin >> n;
vector<Process> p(n);
vector<int> seq;
for (int i = 0; i < n; i++) {
p[i].id = i+1;
cin >> p[i].bt;
seq.push_back(p[i].id); // FCFS sequence = same order
}
printSequence(seq);
p[0].wt = 0;
for (int i = 1; i < n; i++)
p[i].wt = p[i-1].wt + p[i-1].bt;
for (int i = 0; i < n; i++)
p[i].tat = p[i].wt + p[i].bt;
cout << "PID\tBT\tWT\tTAT\n";
for (auto &x : p)
cout << x.id << "\t" << x.bt << "\t" << x.wt << "\t" << x.tat << "\n";
}