package com.ltl.test;
public interface Mystack {
public boolean isEmpty();
public boolean isFull();
public boolean push(int value);
public int pop();
public void show();
}
package com.ltl.test;
public class Stack implements Mystack {
private int maxSize;
private int[] stack;
private int top=-1;
public Stack(int num) {
maxSize=num;
stack=new int[maxSize];
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return top==-1;
}
@Override
public boolean isFull() {
// TODO Auto-generated method stub
return top==maxSize-1;
}
@Override
public boolean push(int value) {
// TODO Auto-generated method stub
if(isFull()) {
System.out.println("栈已满!!!");
return false;
}
top++;
stack[top]=value;
return true;
}
@Override
public int pop() {
// TODO Auto-generated method stub
if(isEmpty()) {
System.out.println("栈空!!");
}
int value=stack[top];
top--;
return value;
}
@Override
public void show() {
// TODO Auto-generated method stub
if(isEmpty()) {
System.out.println("栈空,没有数据!!");
return;
}
for (int i = top; i >= 0; i--) {
System.out.printf("stack[%d]=%d\n",i,stack[i]);
}
}
}
package com.ltl.test;public interface Mystack { public boolean isEmpty(); public boolean isFull(); public boolean push(int value); public int pop(); public void show();}package com.ltl.test;public class Stack implements Mystack { private int.