jvx.util
Class PuQueue
- java.lang.Object
-
- jvx.util.PuQueue
-
public class PuQueue extends java.lang.ObjectThis class provides the functionality of a queue or a stack of integers. Elements can be inserted into the queue, and its youngest and oldest elements can be extracted (Thus, this queue is acting as a "first in first out" queue, or a "last in first out" stack). Internally, the elements are organized within an array, which is automatically expanded if the size is too small. Running time of all operations is O(1); the only exception is the enqueue operation, which has only amortized running time of O(log(n)), due to resizing.- Author:
- Felix Kaelberer
- Version:
- 06.09.09, 1.20 revised (fk) Implemented copyNew().
13.12.06, 1.10 revised (mn) Implemented setSize() and changed the amount of dynamic resizing.
16.01.06, 1.00 created (fk)
-
-
Constructor Summary
Constructors Constructor and Description PuQueue()Construct an empty queue.PuQueue(int size)Construct a queue with array of sizesize.PuQueue(int[] entries)Construct a queue the entries of a given array.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidcopy(PuQueue queue)Copy all properties of the argument tothis.static PuQueuecopyNew(PuQueue queue)Create and return copy ofthis.voidenqueue(int value)Insert an element into the queue.intextractFirst()Get the oldest element of the queue, i.e.the element which was inserted first.intextractLast()Get the youngest element of the queue, i.e.the element which was inserted last.intgetNumEntries()Get number of elements in the queue.intgetSize()Get maximum number of entries of the queue.booleanisEmpty()Whether the queue has no entries.voidremoveAll()Remove all elements from queue.voidsetSize(int size)Set the size of the queue.PiVectortoPiVector()Create a PiVector with the entries of the queue.java.lang.StringtoString()Get a string containing all elements of the queue.
-
-
-
Constructor Detail
-
PuQueue
public PuQueue()
Construct an empty queue.
-
PuQueue
public PuQueue(int size)
Construct a queue with array of sizesize. Initial number of entries is 0.- Parameters:
size- Size of the queue.- Author:
- Felix Kaelberer
- Version:
- 16.01.06, 1.00 created (fk)
-
PuQueue
public PuQueue(int[] entries)
Construct a queue the entries of a given array.- Parameters:
entries- Initial entries of the queue.- Author:
- Felix Kaelberer
- Version:
- 01.02.2007, 1.00 created (fk)
-
-
Method Detail
-
copy
public void copy(PuQueue queue)
Copy all properties of the argument tothis.- Parameters:
queue- The queue to copy.- Author:
- Felix Kaelberer
- Version:
- 16.01.06, 1.00 created (fk)
-
copyNew
public static PuQueue copyNew(PuQueue queue)
Create and return copy ofthis.- Parameters:
queue- The queue to copy.- Author:
- Felix Kaelberer
- Version:
- 30.06.09, 1.00 created (fk)
-
getNumEntries
public int getNumEntries()
Get number of elements in the queue.- Author:
- Felix Kaelberer
- Version:
- 16.01.06, 1.00 created (fk)
-
getSize
public int getSize()
Get maximum number of entries of the queue.- Version:
- 06.12.06, 1.00 created (mn)
-
enqueue
public void enqueue(int value)
Insert an element into the queue. The queue is automatically enlarged, if required.- Parameters:
value- Item to enqueue.- Author:
- Felix Kaelberer
- Version:
- 16.01.06, 1.00 created (fk)
-
setSize
public void setSize(int size)
Set the size of the queue. Existing elements will be copied to the new data structures. If the size is smaller then the number of elements, then then last elements will be removed.- Parameters:
size- New size of the queue.- Author:
- Matthias Nieser
- Version:
- 13.12.06, 1.00 created (mn)
-
extractFirst
public int extractFirst()
Get the oldest element of the queue, i.e.the element which was inserted first.- Author:
- Felix Kaelberer
- Version:
- 16.01.06, 1.00 created (fk)
-
extractLast
public int extractLast()
Get the youngest element of the queue, i.e.the element which was inserted last.- Author:
- Felix Kaelberer
- Version:
- 16.01.06, 1.00 created (fk)
-
toString
public java.lang.String toString()
Get a string containing all elements of the queue.- Overrides:
toStringin classjava.lang.Object- Author:
- Felix Kaelberer
- Version:
- 07.02.07, 1.00 revised (fk) Separate entries with comma, use brackets.
16.01.06, 1.00 created (fk)
-
toPiVector
public PiVector toPiVector()
Create a PiVector with the entries of the queue.- Returns:
- PiVector of size getNumEntries() containing the entries of the queue.;
- Author:
- Felix Kaelberer
- Version:
- 01.02.2007, 1.00 created (fk)
-
removeAll
public void removeAll()
Remove all elements from queue.- Version:
- 06.12.06, 1.00 created (mn)
-
isEmpty
public boolean isEmpty()
Whether the queue has no entries.- Version:
- 06.12.06, 1.00 created (mn)
-
-
"