Hello Im a bit lost n the priority queues and comparator. I dont really see how to make a comparator in java So what I have is giving me a error and what I have read is no help to me http://www.tutorialspoint.com/java/java_using_comparator.htm This post game me some ideas but Im still stuck on how to do it How do I use a PriorityQueue?
What i have is a class that creates an object with a priority, arrival time, and finish time. I also have a number of priority queues to place them into. When i start I place them into the arrival queue to sort them and then see which one came in first and place that into the queue one. But when I try to add a second one to the arrival queue it fails and throws an exception. What I want to do first is to add all the processes to the arrival queue and then sort them so the one with the smallest arrival time will be the first one out of the arrival queue and into the queue one. Thanks for any help with this
//the comparator
Comparator<Integer> comparator = new Comparator();
//priority queues
//only needs 10 elements to hold
PriorityQueue one = new PriorityQueue(10, comparator);
PriorityQueue two = new PriorityQueue(10, comparator);
PriorityQueue three = new PriorityQueue(10, comparator);
PriorityQueue four = new PriorityQueue(10, comparator);
PriorityQueue arrival = new PriorityQueue(10, comparator);
//put all processes in arrival queue
arrival.add(p1);
arrival.add(p2);
arrival.add(p3);
arrival.add(p4);
arrival.add(p5);
arrival.add(p6);
arrival.add(p7);
arrival.add(p8);
arrival.add(p9);
arrival.add(p10);