import java.util.*;
public class Duilie{
public static void main(String[] args){
Queue dl = new Queue();
dl.enq("one");
dl.enq("two");
dl.enq("three");
}
}class Queue extends java.util.Vector {
public Queue(){
super();
}
public synchronized void enq(Object x) {
super.addElement(x);
}
public synchronized Object deq() {
/* 队列若为空,引发EmptyQueueException异常 */
if( this.empty() )
throw new EmptyQueueException();
Object x = super.elementAt(0);
super.removeElementAt(0);
return x;
}
public synchronized Object front() {
if( this.empty() )
throw new EmptyQueueException();
return super.elementAt(0);
}
public boolean empty() {
return super.isEmpty();
}
public synchronized void clear() {
super.removeAllElements();
}
public int search(Object x) {
return super.indexOf(x);
}
}class EmptyQueueException extends java.lang.RuntimeException {
public EmptyQueueException() {
super();
}
}
public class Duilie{
public static void main(String[] args){
Queue dl = new Queue();
dl.enq("one");
dl.enq("two");
dl.enq("three");
}
}class Queue extends java.util.Vector {
public Queue(){
super();
}
public synchronized void enq(Object x) {
super.addElement(x);
}
public synchronized Object deq() {
/* 队列若为空,引发EmptyQueueException异常 */
if( this.empty() )
throw new EmptyQueueException();
Object x = super.elementAt(0);
super.removeElementAt(0);
return x;
}
public synchronized Object front() {
if( this.empty() )
throw new EmptyQueueException();
return super.elementAt(0);
}
public boolean empty() {
return super.isEmpty();
}
public synchronized void clear() {
super.removeAllElements();
}
public int search(Object x) {
return super.indexOf(x);
}
}class EmptyQueueException extends java.lang.RuntimeException {
public EmptyQueueException() {
super();
}
}
public static void main(String[] args) {
Queue dl = new Queue();
dl.enq("one");
dl.enq("two");
dl.enq("three");
while(!dl.empty())
{
String head = (String)dl.firstElement();
dl.deq();
System.out.println(head);
}
}
}class Queue extends java.util.Vector {
public Queue() {
super();
} public synchronized void enq(Object x) {
super.addElement(x);
} public synchronized Object deq() { /* 队列若为空,引发EmptyQueueException异常 */
if (this.empty())
throw new EmptyQueueException();
Object x = super.elementAt(0);
super.removeElementAt(0);
return x;
} public synchronized Object front() {
if (this.empty())
throw new EmptyQueueException();
return super.elementAt(0);
} public boolean empty() {
return super.isEmpty();
} public synchronized void clear() {
super.removeAllElements();
} public int search(Object x) {
return super.indexOf(x);
}
}class EmptyQueueException extends java.lang.RuntimeException {
public EmptyQueueException() {
super();
}
}
写了测试一下,没有错呀