一道java题,求大神帮忙做一下
1个回答
展开全部
定义的接口
public interface StackInterface {
void push(Object value);
Object pop();
boolean isEmpty();
}
实现类:
public class StackImplement implements StackInterface{
private Vector<Object> vector;
public StackImplement(){
this.vector = new Vector<Object>();
}
@Override
public boolean isEmpty() {
return vector.isEmpty();
}
@Override
public Object pop() {
Object obj;
int len = vector.size();
if(len==0){
throw new EmptyStackException();
}
obj = vector.elementAt(len-1);
vector.removeElementAt(len - 1);
return obj;
}
@Override
public void push(Object value) {
vector.addElement(value);
}
}
Stack的底层就是类似实现的!望参考!
public interface StackInterface {
void push(Object value);
Object pop();
boolean isEmpty();
}
实现类:
public class StackImplement implements StackInterface{
private Vector<Object> vector;
public StackImplement(){
this.vector = new Vector<Object>();
}
@Override
public boolean isEmpty() {
return vector.isEmpty();
}
@Override
public Object pop() {
Object obj;
int len = vector.size();
if(len==0){
throw new EmptyStackException();
}
obj = vector.elementAt(len-1);
vector.removeElementAt(len - 1);
return obj;
}
@Override
public void push(Object value) {
vector.addElement(value);
}
}
Stack的底层就是类似实现的!望参考!
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询