编译原理——赋值语句和简单表达式(十五)

来源:互联网 发布:如何寻找淘宝达人合作 编辑:程序博客网 时间:2024/06/05 09:33

二元式栈。

TwoItemStack.java:

package per.eyuan.util;public class TwoItemStack {private TwoItem tis[]=new TwoItem[20];private int top;//栈顶public TwoItemStack() {super();init();}public void init(){for(int i=0;i<tis.length;i++){tis[i]=new TwoItem();}top=-1;}//获取栈中元素的个数public int getLength(){return top+1;}public void push(TwoItem ti){top++;tis[top]=ti;}public TwoItem pop(){if(top==-1){return null;}else{TwoItem tipop=tis[top];top--;return tipop;}}public TwoItem getTop(){if(top==-1)return null;elsereturn tis[top];}public TwoItem getNextTop(){return tis[top+1];}public TwoItem[] getAll(){//返回栈中所有元素if(top==-1){System.out.println("null,the stack is empty");return null;}else{int i=0;TwoItem ati[]=new TwoItem[top+1];for(int ii=0;ii<ati.length;ii++){ati[ii]=new TwoItem();}while(i<=top){ati[i]=tis[i];i++;}return ati;}}public TwoItem[] getHole(){if(top==-1){System.out.println("null,the stack is empty");return null;}else{return tis;}}}


 

原创粉丝点击