/** realizza una coda, usando sue pile. @author Adriano Luchetta @version 21-Nov-2005 @version 3-Dic-2004 */ public class QueueByStacks implements Queue { //parte privata Stack pila; //parte pubblica public QueueByStacks() { pila = new ArStack(); } public boolean isEmpty() { return pila.isEmpty(); } public void makeEmpty() { pila.makeEmpty(); } public int size() { return pila.size(); } public void enqueue(Object obj) { pila.push(obj); } public Object front() throws EmptyQueueException { if (isEmpty()) throw new EmptyQueueException(); Stack tmpPila = new ArStack(); while (!pila.isEmpty()) tmpPila.push(pila.pop()); Object obj = tmpPila.top(); while (!tmpPila.isEmpty()) pila.push(tmpPila.pop()); return obj; } public Object dequeue() throws EmptyQueueException { if (isEmpty()) throw new EmptyQueueException(); Stack tmpPila = new ArStack(); while (!pila.isEmpty()) tmpPila.push(pila.pop()); Object obj = tmpPila.pop(); while (!tmpPila.isEmpty()) pila.push(tmpPila.pop()); return obj; } }