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 { /* 在此插入代码*/ }
}
填充这几个函数
JAVA泛型队列继承泛型栈要如何操作?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
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 (); //这个不需要实现 }
解决 无用评论 打赏 举报
悬赏问题
- ¥20 matlab yalmip kkt 双层优化问题
- ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
- ¥88 实在没有想法,需要个思路
- ¥15 MATLAB报错输入参数太多
- ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
- ¥15 有赏,i卡绘世画不出
- ¥15 如何用stata画出文献中常见的安慰剂检验图
- ¥15 c语言链表结构体数据插入
- ¥40 使用MATLAB解答线性代数问题
- ¥15 COCOS的问题COCOS的问题