您的位置:首页 > 其它

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

2012-03-31 09:29 85 查看
二元式栈。

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;
else
return 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;
}
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: