速度上一定要有提高,头大,实在想不到什么折了。
public interface Tinterface
public Tinterface
public Tinterface
public E peek();
public int size();
}
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
public class Impl
private ArrayList
public Impl(){
queue = new ArrayList
}
public Impl(ArrayList
this.queue = queue;
}
public Tinterface
if(e == null){
throw new IllegalArgumentException();
}
ArrayList
clone.add(e);
return new Impl
}
public Tinterface
if(queue.isEmpty()){
throw new NoSuchElementException();
}
ArrayList
clone.remove(0);
return new Impl
}
public E peek(){
if(queue.isEmpty()){
throw new NoSuchElementException();
}
return queue.get(0);
}
public int size(){
return queue.size();
}
}
重点是要copy一个新队列增删元素,返回这个新队列,最大消耗是这个复制过程。