Il tuo esempio l'ho capito, ma per quanto riguarda quello che ho scritto io ho un dubbio.
Il mio codice non compila, se prendo un altro codice e ne guardo la parte iniziale:
codice:
/* implementa una coda utilizzando un'array */
public class ArrayQueue<E> implements Queue<E> {
private int rear, front;
private int size;
private int n;
private static final int CAPACITY = 100;
private E[] Q;
public ArrayQueue() {
this(CAPACITY);
}
public ArrayQueue(int capacity) {
rear = front = 0;
size = 0;
n = capacity;
Q = (E[]) new Object[capacity]; //genera un'eccezione ma ĆØ ok
}
public boolean isEmpty() {
if(size==0) return true;
return false;
}
public int size() {
return size;
}
public E front() throws EmptyQueueException{
if (isEmpty()) throw new EmptyQueueException("Queue is empty.");
return Q[front];
}
public void enqueue(E elem) {
if(size()==n) throw new FullQueueException("Queue is full.");
Q[rear] = elem;
rear = (rear+1) % n;
size++;
}
public E dequeue() throws EmptyQueueException {
if (size == 0) throw new EmptyQueueException("Queue is empty.");
E tmp = Q[front];
Q[front] = null;
front = (front+1) % n;
return tmp;
}
}
E' questo il codice che non capivo, perchč il primo costruttore dovrebbe impostare come default la capacitą dello stack, ma ora che tu mi hai spiegato forse mi č chiaro.
La imposta di default con il valore CAPACITY perchč il primo costruttore richiama il secondo o sbaglio?