public class Queue extends Stack{
public final int dump=1024;
private Stack stk;
public Queue( ){ stk = new Stack(); }
public boolean add(E e) throws IllegalStateException, ClassCastException,
NullPointerException, IllegalArgumentException{ stk.push(e); return true; }
public boolean offer(E e) throws ClassCastException, NullPointerException,
IllegalArgumentException { return this.add(e); }
public E remove() throws NoSuchElementException { synchronized(this) {
if (!this.isEmpty()) { return super.pop(); } else { while(!stk.isEmpty()) this.push(stk.pop()); return super.pop(); } }
}
public E poll( ) { return this.remove(); }
public E peek ( ) {
synchronized(this) { if (!this.isEmpty()) { return super.peek(); } else { while(!stk.isEmpty()) super.push(stk.pop()); return super.peek(); } }
}
public E element( ) throws NoSuchElementException { throws new NoSuchElementException (); //这个不需要实现 }
}