public class PriorQueueNode { private int priority; protected Queue data; protected PriorQueueNode link; public PriorQueueNode() { } public PriorQueueNode(Queue q, int p) { data = q; priority = p; } public int getPriority() { return priority; } } public class PriorityQueue { public PriorityQueue() { } private PriorQueueNode head; public void insert (Object o) { Queue qNew; // check for empty queue if (empty()) { qNew = new Queue(); qNew.insert(o); int p = ((Prioritizable) o).getPriority(); head = new PriorQueueNode(qNew, p); return; } // non-empty queue PriorQueueNode prev = head; PriorQueueNode next = head; int p = ((Prioritizable) o).getPriority(); while (next != null) { int prior = next.getPriority(); if (p == prior) { // Queue exists with given priority next.data.insert(o); return; } else if (p > prior) { return; } else { } } // insert at end of queue } public boolean empty() { return head == null; } public Object peek() { if (head == null) throw new NullPointerException(); else { Queue tempQ = head.data; return tempQ.peek(); } } public Object remove() { } } public String toString() { PriorQueueNode next = head; String str = "{"; while (next != null) { str = str + next.data.toString() + " "; next = next.link; } return str + "}"; } }