package 栈顺序结构及功能实现;
public class Stack {
int top;
int[] stack=new int[50];
public Stack(){
top=-1;
}
public void push(int data){
if(top>=stack.length-1) {
return ;
}
else {
top++;
stack[top]=data;
}
}
public void pop(){
if(top==-1) {
return ;
}
else {
int i;
i=stack[top];
top--;
System.out.println("删除的栈顶元素为"+i);
}
}
public void display() {
if(top==-1) {
System.out.println("该栈目前是空栈");
}
else {
for(int i=0;i<=top;i++) {
System.out.print(stack[i]+" ");
}
System.out.println();
}
}
public static void main(String args[]) {
Stack newstack=new Stack();
newstack.push(20);
newstack.push(30);
newstack.display();
newstack.pop();
newstack.pop();
newstack.display();
}
}