JVA栈算法的实现
//*
package com.yza.struct;
//*
公共类堆栈{
int索引=-1;
int size;
布尔输入;
公共堆栈
this(10;
}
公共堆栈(intsize ) {
this.size=size;
if(size=0) {
} else {
this.size=size;
objArr=new Object[this.size];
}
}
//将元素添加到堆栈中
公共语音推送(对象) {
If (索引!=size
} else {//如果超过原始堆栈的大小,则推出底部
for(intI=0; i size - 1; I ) {
}
if (索引----==0) {
索引=0;
}
}
}
//要堆栈的对象
公共对象pop () {
If (索引!=0}{
o=objArr[index];
} else {
o=objArr[0];
}
返回o;
}
公共布尔输入
isEmpty=false;
if(objARR[0]==null () () ) ) ) ) )。
isEmpty=true;
返回时间;
}
publicstaticvoidmain (字串冷傲的大豆args ) )。
堆叠=新堆叠(;
sack.push (新对象) );
sack.push (新对象) );
stack.pop (;
}
}