E - element type.public class AdjustablePriorityQueue<E extends java.lang.Comparable>
extends java.lang.Object
BTreeNode
holding the element. Thus offer will return BTreeNode of the new element.
Elements are prioritized by their natural order (Comparable).
You must ensure that when the priority of an element is improved / demoted you call
improvePriority() / decreasePriority(), respecticely.| Constructor and Description |
|---|
AdjustablePriorityQueue()
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
decreasePriority(BTreeNode<E> x)
Fix the priority queue after the priority of the element
in
BTreeNode has been changed to worse one. |
void |
improvePriority(BTreeNode<E> node)
Fix the priority queue after the priority of the element
in
BTreeNode has been changed to better one. |
boolean |
isEmpty()
Operation to check if priority queue is empty or not.
|
BTreeNode<E> |
offer(E x)
Inserts an element to priority queue.
|
E |
poll()
Remove and return the most important element of the priority queue.
|
java.lang.String |
toString()
String representation of priority queue.
|
public AdjustablePriorityQueue()
public BTreeNode<E> offer(E x)
x - the element to be inserted.BTreeNode holding the element.public E poll()
NoSuchMethodException if there are no elements.public void improvePriority(BTreeNode<E> node)
BTreeNode has been changed to better one.node - the node containing the element which was changed.public void decreasePriority(BTreeNode<E> x)
BTreeNode has been changed to worse one.node - the node containing the element which was changed.public boolean isEmpty()
public java.lang.String toString()
toString in class java.lang.Object