package com;
/** 栈共享(顺序储存结构)
*/
public class LinearTable {
static int MAXSIZE=11;
int top;
int top2=MAXSIZE;
Object[] objArray=new Object[MAXSIZE];
/**
*
* @param stackNumber 辨别栈1,栈2
* @param ob
*/
public void push(int stackNumber,Object ob){
if((top+1)==top2){
throw new IndexOutOfBoundsException(" 栈满了 ");
}
if(stackNumber==1){
objArray[top]=ob;
top++;
}else{
top2--;
objArray[top2]=ob;
}
}
public Object pop(int stackNumber){
Object obj = null;
if(stackNumber==1){
if(top!=0){
top--;
obj=objArray[top];
objArray[top]=null;
}
}else{
if(top2!=(MAXSIZE-1)){
obj=objArray[top2];
objArray[top2]=null;
top2++;
}
}
return obj;
}
public static void main(String[] args) {
LinearTable l=new LinearTable();
l.push(1, "1");
l.push(1, "2");
l.push(1, "3");
l.push(1, "4");
l.push(1, "5");
l.push(2, "1");
l.push(2, "2");
l.push(2, "3");
l.push(2, "4");
l.push(2, "5");
l.pop(1);
l.pop(1);
l.pop(1);
l.pop(2);
l.pop(2);
l.pop(2);
System.out.println();
}
}