qq_36466220 2018-05-06 05:13 采纳率: 0%
浏览 1336
已结题

JAVA泛型队列继承泛型栈要如何操作?

import java.util.Stack;
import java.util.NoSuchElementException;
public class Queue extends Stack{
public final int dump=1024;
private Stack stk;
public Queue( ){ /* 在此插入代码*/ }
public boolean add(E e) throws IllegalStateException, ClassCastException,
NullPointerException, IllegalArgumentException{ /* 在此插入代码*/ }
public boolean offer(E e) throws ClassCastException, NullPointerException,
IllegalArgumentException{ /* 在此插入代码*/ }
public E remove( ) throws NoSuchElementException { /* 在此插入代码*/ }
public E poll( ) { /* 在此插入代码*/ }
public E peek ( ) { /* 在此插入代码*/ }
public E element( ) throws NoSuchElementException { /* 在此插入代码*/ }
}
填充这几个函数

  • 写回答

3条回答

  • threenewbee 2018-05-06 06:19
    关注
     public Queue( ){ stk = new stk(); }
    public boolean add(E e) throws IllegalStateException, ClassCastException, 
    NullPointerException, IllegalArgumentException{ this.push(e); }
    public boolean offer(E e) throws ClassCastException, NullPointerException, 
    IllegalArgumentException{ return this.size() > 0; }
    public E remove( ) throws NoSuchElementException { return this.pop(); }
    public E pull( ) { while ( E e = this.pop()) this.stk.push(e);
    E r = e;
    while ( E e =stk.pop()) this.push(e);
    return r;
    }
    public E peek ( ) { return this.peek(); }
    public E element( ) throws NoSuchElementException {
    throws new NoSuchElementException (); //这个不需要实现
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题