Copia

void process::Prioridad() { // Hacer una copia de la cola original node* originalQueue = nullptr; node* tail = nullptr; node* p = head; while (p != nullptr) { node* newNode = new node(p->id(), p->tme(), p->prty()); if (originalQueue == nullptr) { originalQueue = newNode; tail = newNode; } else { tail->next(newNode); tail = newNode; } p = p->next(); } // Ordenar la copia por prioridad node* sortedCopy = nullptr; while (originalQueue != nullptr) { node* maxNode = originalQueue; node* prevMaxNode = nullptr; node* current = originalQueue->next(); node* prev = originalQueue; while (current != nullptr) { if (current->prty() > maxNode->prty()) { maxNode = current; prevMaxNode = prev; } prev = current; current = current->next(); } // Sacar el nodo máximo de la lista original if (prevMaxNode != nullptr) { prevMaxNode->next(maxNode->next()); } else { originalQueue = maxNode->next(); } // Insertar el nodo máximo al principio de la lista ordenada maxNode->next(sortedCopy); sortedCopy = maxNode; } // Procesar y mostrar la cola ordenada // Aquí deberías colocar el código de procesamiento y salida // Asegúrate de trabajar con la lista ordenada (sortedCopy) // Liberar la memoria ocupada por la copia de la cola original y la lista ordenada while (originalQueue != nullptr) { node* temp = originalQueue; originalQueue = originalQueue->next(); delete temp; } while (sortedCopy != nullptr) { node* temp = sortedCopy; sortedCopy = sortedCopy->next(); delete temp; }
}
Enter fullscreen mode
Exit fullscreen mode

Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top
Cafe blend decaf 12oz ground coffee near me | near me direct | directory. Social media service. Us gpu plans.