求java大神,创建栈的类。。。
发布网友
发布时间:2023-10-12 13:03
我来回答
共1个回答
热心网友
时间:2024-12-05 10:41
public class stack{
private int length = 10;
private List<Double> list = new ArrayList<Double>();//list 存放
private int top;//指示栈顶位置的变量
//初始化
public stack(){
top=0;}
public void push(double x) {//入栈
if (top==length){
System.out.println("Stack is full !");
return ;
}
list.add(x);
top ++;
}
public double pop(){
top--;
if(top<0){
System.out.println("Stack is underflow ");
thrown new NoMoreElementEXception("Stack is underflow");
}
return list.remove(1);
}
参考C语言。http://zhidao.baidu.com/question/291734752.html