Skip to content

Instantly share code, notes, and snippets.

@alvareztech
Last active September 14, 2016 04:15
Show Gist options
  • Save alvareztech/e40fade88aefd8a6bcc4b77723f7f20c to your computer and use it in GitHub Desktop.
Save alvareztech/e40fade88aefd8a6bcc4b77723f7f20c to your computer and use it in GitHub Desktop.
Sugerencia solución
// SUGERENCIA DE SOLUCIÓN
Queue<Vehiculo> colaVehiculos = new LinkedList<Vehiculo>();
Queue<Soat> colaPrioridadSoats = new PriorityQueue<Soat>(); // Clase Soat debe ser comparable
Queue<Soat> tempColaPrioridadSoats = new PriorityQueue<Soat>();
// adicionar datos a las colas (no a la temporal)
while (!colaPrioridadSoats.isEmpty()) {
Soat s = colaPrioridadSoats.remove();
int n = colaVehiculos.size();
for (int i = 0; i < n; i++) {
Vehiculo v = colaVehiculos.remove();
v.setSoat(s);
colaVehiculos.add(v);
}
tempColaPrioridadSoats.add(s);
}
while (!tempColaPrioridadSoats.isEmpty()) {
Soat s = tempColaPrioridadSoats.remove();
colaPrioridadSoats.add(s);
}
// mostrar la cola de vehiculos con toda la información
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment