Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package homework.pkg6;
- /**
- *
- * @author Steven
- */
- public class PriorityQueue<E> {
- private ArrayQueue<E>[] queues;
- private int highest_queue;
- private int totalSize;
- public PriorityQueue(int highest)
- {
- queues = new ArrayQueue[highest + 1];
- for(int i =0; i < (highest+1); i++)
- {
- queues[i] = new ArrayQueue<E>();
- }
- //queues = new ArrayQueue<E>(highest+1);
- highest_queue = highest;
- }
- public void add(E item, int priority)
- {
- if(priority > 0 && priority < highest_queue)
- {
- queues[priority].add(item);
- }
- if(priority > highest_queue)
- {
- highest_queue = priority;
- queues[priority].add(item);
- }
- totalSize++;
- }
- public E removeQ()
- {
- E item = null;
- if(!(queues[highest_queue].isEmpty()))
- {
- item = queues[highest_queue].remove();
- }
- return(item);
- }
- public E peek()
- {
- return ((E) queues[highest_queue]);
- }
- public int size()
- {
- return totalSize;
- }
- }
Add Comment
Please, Sign In to add comment