62,620
社区成员
发帖
与我相关
我的任务
分享
package DateStruct;
public class stack<E> {
private Object[] a;
private int top = -1;
public stack(int size){
a = new Object[size];
//ArrayList a = new ArrayList();
}
public void push(E i) throws Exception{
if(isFull() == false){
top++;
a[top] = i;
}else{
throw new Exception("stack is full");
}
}
public E pop() throws Exception{
if(isEmpty() == false){
top--;
return (E) a[top+1]; //就是出现警告的地方。
}else{
throw new Exception("stack is empty");
}
}
private boolean isEmpty(){
if(top < 0)return true;
else return false;
}
private boolean isFull(){
if(top+1 > a.length)return true;
else return false;
}
public int getNumbers(){
return top+1;
}
}