package com;
/** 栈
*/
public class LinearTable {
static int MAXSIZE=5;
int top;
Object[] objArray=new Object[MAXSIZE];
public void push(Object ob){
if(top==(MAXSIZE-1)){
throw new IndexOutOfBoundsException(" MAXSize: "+MAXSIZE);
}
objArray[top]=ob;
top++;
}
public Object pop(){
Object obj = null;
if(top!=0){
obj=objArray[top];
objArray[top]=null;
top--;
}
return obj;
}
public static void main(String[] args) {
LinearTable l=new LinearTable();
l.push("1");
l.push("2");
l.push("3");
l.pop();
l.push("4");
l.push("5");
System.out.println();
}
}
java数据结构 五(栈)
最新推荐文章于 2019-07-21 12:34:00 发布