栈
来源:互联网 发布:oracle数据库备份owner 编辑:程序博客网 时间:2024/04/28 13:00
class Stack {
private long[] s;
private int top;
private int length;
public Stack(int length){
this.length = length;
s = new long[length];
top = -1;
}
public void push(long item){
s[++top] = item;
// top++;
// s[top] = item;
}
public long pop(){
return s[top--];
}
public long seek(long searchkey){
return s[top];
}
public boolean isEmpty(){
return (top==-1);
}
public boolean isFull(){
return (top==length-1);
}
}
class StackApp{
public static void main(String[] args){
Stack s = new Stack(10);
s.push(0);
s.push(28);
s.push(11);
s.push(21);
s.push(28);
s.push(2);
s.push(4);
s.push(6);
s.push(11);
s.push(1);
while(!s.isEmpty()){
long value = s.pop();
System.out.println(value);
}
}
}