-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsjf.cpp
More file actions
39 lines (37 loc) · 1.15 KB
/
sjf.cpp
File metadata and controls
39 lines (37 loc) · 1.15 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
#include <bits/stdc++.h>
#include "processinho.hpp"
#include "sjf.hpp"
using namespace std;
bool cmp2(processo a, processo b){
return a.duracao < b.duracao;
}
void sjf(processo * vet, int numeroDeProcessos){
processo chegaram[numeroDeProcessos];
int tempo=vet[0].chegada, cont=0, n=numeroDeProcessos;
float turnaround=0;
string res;
for (int j=0; j<tempo; j++)
res+="_";
while(n){
while(vet[cont].chegada<=tempo){
chegaram[cont]=vet[cont];
cont++;
}
sort(chegaram, chegaram+cont, cmp2);
cout << vet[numeroDeProcessos-n].nome;
for (int j=0; j<vet[numeroDeProcessos-n].duracao; j++)
res+="|";
for (int j=0; j<res.size(); j++)
if (numeroDeProcessos-n>0 && j==vet[numeroDeProcessos-n].chegada && res[j]=='_') res[j]='*';
cout << ": " << res << endl;
vet[numeroDeProcessos-n].tempo=res.size()-vet[numeroDeProcessos-n].chegada;
tempo=vet[numeroDeProcessos-n].tempo;
turnaround+=tempo;
for (int j=0; j<res.size(); j++)
res[j]='_';
n--;
}
for (int i=0; i<numeroDeProcessos; i++)
cout << "Tempo de espera de " << vet[i].nome << " " << vet[i].tempo << endl;
cout << "Turnaround medio " << turnaround/numeroDeProcessos << endl;
}