public class AssignablePriorityQueue<E>
extends java.lang.Object
AssignablePriorityQueuewould produceapq = new AssignablePriorityQueue (); apq.add("four", 4); apq.add("eighteen", 18); apq.add("gazillion", -1); apq.add("two", 2); String polled; while ((polled = apq.poll()) != null) { System.out.print(polled); System.out.print(" "); } System.out.println();
gazillion two four eighteen
PriorityQueue
Constructor and Description |
---|
AssignablePriorityQueue()
Creates an AssignablePriorityQueue with the default initial
capacity (11) that orders its elements according to the natural
ordering of their assigned priorities.
|
AssignablePriorityQueue(int initialCapacity)
Creates an AssignablePriorityQueue with the specified initial
capacity (11) that orders its elements according to the natural
ordering of their assigned priorities.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(E element,
float priority)
Inserts a specified element to the priority queue with the specified
priority.
|
boolean |
add(float priority,
E element)
Deprecated.
Use
add(E element, float priority) instead.
|
void |
clear()
Remove all elements from the priority queue.
|
java.util.Iterator<E> |
iterator()
Returns an iterator over the elements in this queue.
|
E |
peek()
Retrieves, but does not remove, the head of this queue,
returning null if this queue is empty.
|
E |
poll()
Removes and returns the head of this queue, or null
if this queue is empty.
|
int |
size()
Returns the number of elements in this queue.
|
public AssignablePriorityQueue()
public AssignablePriorityQueue(int initialCapacity)
public boolean add(float priority, E element)
priority
- the priority to be assigned to the elementelement
- the element to be insertedjava.lang.NullPointerException
- if the specified element is nullpublic boolean add(E element, float priority)
priority
- the priority to be assigned to the elementelement
- the element to be insertedjava.lang.NullPointerException
- if the specified element is nullpublic java.util.Iterator<E> iterator()
public int size()
public void clear()
public E poll()
public E peek()