java实现栈的基本操作
package arithmetic;
import java.io.PushbackInputStream;
public class MyStack {
private static int SIZE=10;
private int top;
private Object[] contents;
public MyStack(){
top=0;
contents=new Object[SIZE];
}
public boolean empty(){
if(top==0){
System.out.println("栈空了!");
return true;
}
else{
return false;
}
}
public boolean full(){
if(top==SIZE){
System.out.println("栈满了!");
return true;
}else{
return false;
}
}
public void push(Object o){
if(full()==false){
contents[top]=o;
top++;
}
}
public Object pop(){
if(empty()==false){
Object result =contents[top-1];
contents[top-1]=null;
top--;
return result;
}
else{
return null;
}
}
}
入门级~