-
Notifications
You must be signed in to change notification settings - Fork 1
/
SJF.cpp
105 lines (80 loc) · 1.47 KB
/
SJF.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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
ifstream ar;
void inicializar();
void ver();
typedef struct nodo {
char nom[10];
int t;
nodo *sig;
}NODO;
NODO *r,*act;
void inicializar(){
ar.open("procesos.txt");
NODO *ant = NULL;
r = new NODO;
if (!ar.eof()){
ar>>r->nom;
ar>>r->t;
r->sig = NULL;
}
while (!ar.eof()){
NODO *aux;
NODO *Q = new NODO;
ar>>Q->nom;
ar>>Q->t;
Q->sig = NULL;
act = r;
while (act !=NULL){
if (Q->t < act->t){
if (ant != NULL )ant->sig = Q;
Q->sig = act;
if (act == r ) r = Q;
break;
}
ant= act;
act = act->sig;
}
if (act == NULL) {
act=r;
while (act->sig != NULL) act= act->sig;
act->sig = Q;
}
}
ar.close();
}
void ver(){
NODO *a = r;
if (a != NULL){
cout<<"N: "<<a->nom<<" t: "<<a->t<<endl;
while (a->sig != NULL){
a = a->sig;
cout<<"N: "<<a->nom<<" t: "<<a->t<<endl;
}
}
}
void SJF(){
inicializar();
ver();
cout<<endl;
NODO *ant;
int tr =0,x=0;
float prom=0;
while (r !=NULL){
x++;
tr += r->t;
cout<<"TR"<<r->nom<<" = "<<tr<<endl;
prom += tr;
ant = r;
r = r->sig;
delete ant;
}
(x!=0)?cout<<"TR Promedio "<<float(prom/x)<<endl: cout<<"0";
}
int main(){
SJF();
system("pause");
return 0;
}