/** * QueueClass.java * Perry Holloway * */ // Declaration of QueueClass class QueueClass { int MAX_QUEUE = 100; // Global variable -- max array size // QueueClass Constructor public QueueClass() { Front = null; Rear = null; Count = 0; Previous = null; }// end of constructor // Boolean method if the Queue is Empty public boolean QueueIsEmpty() { return (Count == 0); } // This is a method that was added to return the length of the Queue public int length() { return Count; } //Redoing the QueueAdd to make it work as a priority queue public void QueueAdd(Event event) { // This is the case when the queue is empty and nothing to compare it to if(Front == null) { Front = event; Rear = event; ++Count; }// end of the if // this is the case where there is already stuff in the queue // and the new event has a lower time then the front else if(Front.get_arrival_time() >= event.get_arrival_time()) { event.next = Front; Front = event; ++Count; } // end of the case where you replace the front with new event // This is the case where the new event is has a greater arrival time // than everything in the Queue else if(Rear.get_arrival_time() <= event.get_arrival_time()) { event.next = null; Rear.next = event; Rear = event; ++Count; } // end of the case // The case where it will have to place event in the correct position else { Previous = Front; while(Previous != null) { if(event.get_arrival_time() > Previous.next.get_arrival_time()) { Previous = Previous.next; } else { break;// to end the loop } } // End of the While loop event.next = Previous.next; Previous.next = event; ++Count; } // End of the Else }// end QueueAdd // This is a method to Remove an Event from the Queue public void QueueRemove() { // queue is not empty; remove front if (Front != null) { Front = Front.next; if(Front == null) { Rear = null; } --Count; }// end if }// end QueueRemove public Event GetQueueFront() { boolean Success = (!QueueIsEmpty()); //System.out.println("Count = " + Count); if (Success) { // queue is not empty; retrieve front return Front; } else { //System.out.println("Count is suppose to be 0 but is = " + Count); //System.out.println("Failure in GetQueueFront "); Event Event_Null = new Event(); Event_Null = null; return Event_Null; } } // end GetQueueFront //Event[] Items = new Event[MAX_QUEUE]; private Event Front; private Event Rear; private Event Previous; int Count; } // end QueueClass