Class PriorityQueue
java.lang.Object
smile.util.PriorityQueue
Priority Queue for index items.
-
Constructor Summary
ConstructorsConstructorDescriptionPriorityQueue(double[] a) Constructor.PriorityQueue(int d, double[] a) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidchange(int k) The priority of item k has changed.voidinsert(int v) Insert a new item into queue.booleanisEmpty()Returns true if the queue is empty.voidlower(int k) The value of item k is lower (higher priority) now.intpoll()Removes and returns the index of item with minimum value (highest priority).
-
Constructor Details
-
PriorityQueue
public PriorityQueue(double[] a) Constructor. Default use a 3-heap.- Parameters:
a- external array of priority. Lower value means higher priority.
-
PriorityQueue
public PriorityQueue(int d, double[] a) Constructor.- Parameters:
d- d-heap.a- external array of priority. Lower value means higher priority.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Returns true if the queue is empty.- Returns:
- true if the queue is empty.
-
insert
public void insert(int v) Insert a new item into queue.- Parameters:
v- the index of item.
-
poll
public int poll()Removes and returns the index of item with minimum value (highest priority).- Returns:
- the index of item with minimum value.
-
lower
public void lower(int k) The value of item k is lower (higher priority) now.- Parameters:
k- the item index.
-
change
public void change(int k) The priority of item k has changed.- Parameters:
k- the item index.
-