void process::Prioridad() {
//se ordena por prioridad
node *p = head;
while (p != nullptr) {
node *q = p -> next();
while (q != nullptr) {
if (q -> prty() > p -> prty()) {
char idx = p -> id();
int tmex = p -> tme();
int prtyx = p -> prty();
p -> setid(q -> id());
p -> settme(q -> tme());
p -> setprty(q -> prty());
q -> setid(idx);
q -> settme(tmex);
q -> setprty(prtyx);
}
q = q -> next();
}
p = p -> next();
}
node *r = head;
float tR = 0, tRT = 0;
int Q = calcQ();
cout << "\n\tId //" << " Tiempo de ejecucion //" << " Prioridad //" << " Tiempo de retorno //" << " Procesos restantes (ID Tiempo Prioridad)" << endl;
while (r != nullptr) {
if (r -> tme() <= Q) {
tR += r -> tme();
tRT += tR;
cout << "\t"<< r -> id() << "\t\t"<< r -> tme()<< "\t\t"<< r -> prty()<< "\t\t"<< tR<< "\t\t";
node *t = r -> next();
while(t != nullptr){
std::cout << " | " << t -> id() << " " << t -> tme() << " " << t -> prty() << " | ";
t = t -> next();
}
cout << endl;
r = r -> next();
}else{
tR += Q;
r -> settme(r -> tme() - Q);
r -> setprty(r -> prty() - 1);
node *t = r;
while(t -> next() != nullptr && t -> next() -> prty() == r -> prty()){
t = t -> next();
}
r -> next(t -> next());
t -> next(r);
cout << "\t"<< r -> id() << " no terminado\t\t"<< r -> tme()<< "\t\t"<< r -> prty()<< "\t\t"<< tR<< "\t\t";
cout << endl;
}
}
cout << "\n\tTiempo promedio: "<< (float)tRT/n<< endl;
cout << "\n\tQuantum: "<< Q<< endl;
}
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)