apuntelebien
Published: 2024-04-19 23:08:41

https://dev.to/imnotleo/respaldo-del-codigo-de-so-xd-3nkg

quitar el s de size en hpp



```
            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";
         
            node *x = r -> next();
            while (x != nullptr) {
                
            std::cout << " | " << x -> id() << " " << x -> tme() << " " << x -> prty() << " | ";
            x = x -> next();
            }
         
          cout << endl;
```



```
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);
            cout << "\t"<< r -> id() << " pendiente     "<< r -> tme()<< "\t\t"<< r -> prty()<< "\t\t"<< tR<< "\t\t";
            node *t = r;
      while(t != nullptr){
      std::cout << " | " << t -> id() << " " << t -> tme() << " " << t -> prty() << " | ";
      t = t -> next();
            }
            cout << endl;
            /*
            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";
         
            node *x = r -> next();
            while (x != nullptr) {
                
            std::cout << " | " << x -> id() << " " << x -> tme() << " " << x -> prty() << " | ";
            x = x -> next();
            }
         
          cout << endl;
          */
            }
          
      }

      cout << "\n\tTiempo promedio: "<< (float)tRT/n<< endl;
      cout << "\n\tQuantum: "<< Q<< endl;
      

  }
```


```
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);
        cout << "\t" << r->id() << " pendiente     " << r->tme() << "\t\t" << r->prty() << "\t\t" << tR << "\t\t";
        node *t = r;
        while (t != nullptr) {
            std::cout << " | " << t->id() << " " << t->tme() << " " << t->prty() << " | ";
            t = t->next();
        }
        cout << endl;
        
        // Aquí vamos a reordenar la lista si es necesario
        node *t2 = r;
        while (t2->next() != nullptr && t2->next()->prty() > r->prty()) {
            t2 = t2->next();
        }
        if (t2 != r) {
            node *temp = r->next();
            r->next(t2->next());
            t2->next(r);
            r = temp;
        } else {
            r = r->next();
        }
    }
}

cout << "\n\tTiempo promedio: " << (float)tRT / n << endl;
cout << "\n\tQuantum: " << Q << endl;
```