Skip to content

Instantly share code, notes, and snippets.

@bchetty
Created March 25, 2016 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bchetty/1ae4217e90760f2af9fc to your computer and use it in GitHub Desktop.
Save bchetty/1ae4217e90760f2af9fc to your computer and use it in GitHub Desktop.
PQueueTest.java
import com.chetty.algos.data.Patient;
import java.util.Comparator;
import java.util.PriorityQueue;
/**
*
* @author Babji Prashanth, Chetty
*/
public class PQueueTest {
public static void main(String[] args) {
PriorityQueue<Patient> patientQueue = new PriorityQueue<Patient>(10, new Comparator() {
public int compare(Patient patient1, Patient patient2) {
return (patient1.isEmergencyCase() == patient2.isEmergencyCase()) ? (Integer.valueOf(patient1.getId()).compareTo(patient2.getId()))
: (patient1.isEmergencyCase() ? -1 : 1);
}
});
patientQueue.add(new Patient(1, "Patient1", false));
patientQueue.add(new Patient(2, "Patient2", false));
patientQueue.add(new Patient(3, "Patient3", true));
patientQueue.add(new Patient(4, "Patient4", false));
patientQueue.add(new Patient(5, "Patient5", true));
System.out.println();
System.out.print("Doctor's waiting for patients : ");
while(true) {
Patient currentPatient = patientQueue.poll();
if(currentPatient == null) {
break;
}
System.out.print(currentPatient.getName() + " <-- ");
}
System.out.println();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment