Created
March 25, 2016 22:15
-
-
Save bchetty/1ae4217e90760f2af9fc to your computer and use it in GitHub Desktop.
PQueueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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