日期:2014-05-20 浏览次数:20951 次
/*自己定义的栈,为了可以自由的访问栈中的元素。
* */
class MyStack{
String[] st=new String[10];
int top=0;
void push(String vex){
if(top==st.length-1){ //栈满时,给栈扩容
String[] st1=new String[st.length+10];
System.arraycopy(st, 0, st1, 0, st.length-1);
st=st1;
}
st[top++]=vex;
}
boolean isEmpty() {
if(top==0) return true;
return false;
}
String pop(){
if(top==0){
return null;
}else{
return st[--top];
}
}
public String toString(){
String s="";
for(int i=0;i<top;i++){
s=s+st[i]+" ";
}
return s;
}
}