-
Notifications
You must be signed in to change notification settings - Fork 1
/
Robin.cpp
117 lines (88 loc) · 1.56 KB
/
Robin.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
106
107
108
109
110
111
112
113
114
115
116
117
#include <iostream>
#include <fstream>
using namespace std;
ifstream ar;
void ver();
typedef struct nodo {
char nom[10];
int t;
nodo *sig;
}NODO;
NODO *r, *act;
int qu;
void inicializar(){
ar.open("procesos.txt");
if (!ar.eof()){
r = new NODO;
ar>>r->nom;
ar>>r->t;
r->sig=NULL;
act = r;
}
while(!ar.eof()){
NODO *q =new NODO;
ar>>q->nom;
ar>>q->t;
q->sig = NULL;
act->sig = q;
act = act->sig;
}
}
int techo(){
NODO *ini = r;
int suma=0,x=0;
while (ini != NULL) {
suma += ini->t;
x++;
ini = ini->sig;
}
return suma/x;
}
void ver(){
NODO *ini;
ini = r;
while (ini != NULL){
cout<<"nombre"<<ini->nom<<" : "<<ini->t<<endl;
ini=ini->sig;
}
}
void robin(){
NODO *ini;
NODO *fin = r;
int t=0,x=0;
float prom=0;
ini = r;
while (fin->sig != NULL) fin = fin->sig;
while (r!=NULL){
if (ini->t <= qu){
t += ini->t;
x++;
prom += t;
cout<<"Tr"<<ini->nom<<"="<<t<<endl;
r = r->sig;
NODO *act = ini;
ini = ini->sig;
delete act;
}else{
ini->t -= qu;
t += qu;
cout<<"Pasaron "<<qu <<" segundos... ";
cout<<"N "<<ini->nom<<"T "<<ini->t<<endl;
NODO *act = ini;
ini = ini->sig;
act->sig = NULL;
fin->sig = act;
fin = fin ->sig;
}
}
(x!=0)?cout<<"TR Promedio "<<float(prom/x)<<endl: cout<<"0";
}
int main(){
inicializar();
ver();
qu = techo();
cout<<endl<<"Quamtum "<<techo()<<endl<<endl;
robin();
system("pause");
return 0;
}