lab2
Class ArrayQueue
java.lang.Object
|
+--lab2.ArrayQueue
- All Implemented Interfaces:
- Queue
- public class ArrayQueue
- extends java.lang.Object
- implements Queue
Classe ArrayQueue:
Realizzazione della coda come array circolare, utilizzando una
specifica analoga a Stack
in Java Collections API.
- See Also:
Queue
Constructor Summary |
ArrayQueue()
Costruttore della coda. |
Method Summary |
void |
clear()
Svuota la coda. |
java.lang.Object |
dequeue()
Rimuove e restituisce l'oggetto in testa alla coda. |
protected void |
doubleQueue()
|
java.lang.Object |
enqueue(java.lang.Object x)
Inserisce un oggetto in fondo alla coda. |
java.lang.Object |
front()
Restituisce l'oggetto in testa alla coda senza estrarlo. |
protected int |
increment(int x)
|
boolean |
isEmpty()
Verifica che la coda sia logicamente vuota. |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
DEFAULT_SIZE
static final int DEFAULT_SIZE
theArray
protected java.lang.Object[] theArray
size
protected int size
front
protected int front
back
protected int back
ArrayQueue
public ArrayQueue()
- Costruttore della coda.
isEmpty
public boolean isEmpty()
- Verifica che la coda sia logicamente vuota.
- Specified by:
isEmpty
in interface Queue
- Returns:
true
se la coda è vuota;
false
altrimenti.
clear
public void clear()
- Svuota la coda.
- Specified by:
clear
in interface Queue
front
public java.lang.Object front()
- Restituisce l'oggetto in testa alla coda senza estrarlo.
- Specified by:
front
in interface Queue
- Returns:
- l'oggetto in testa.
- Throws:
EmptyQueueException
- con coda vuota.
enqueue
public java.lang.Object enqueue(java.lang.Object x)
- Inserisce un oggetto in fondo alla coda.
- Specified by:
enqueue
in interface Queue
- Parameters:
x
- l'oggetto da inserire.- Returns:
- l'oggetto inserito.
- Throws:
java.lang.IllegalArgumentException
- se l'argomento passato
è null
.
dequeue
public java.lang.Object dequeue()
- Rimuove e restituisce l'oggetto in testa alla coda.
- Specified by:
dequeue
in interface Queue
- Returns:
- l'oggetto in testa.
- Throws:
EmptyQueueException
- con coda vuota.
doubleQueue
protected void doubleQueue()
increment
protected int increment(int x)