/**
* 顺序结构栈
*
*/
public class SeqStack {
private final int SIZE=10;
private int[] stack=new int[SIZE];
private int top=0;
//入栈
public boolean push(int elem){
if(top==SIZE){
return false;
}else{
stack[top]=elem;
top++;
return true;
}
}
//是否为空
public boolean isEmpty(){
if(top==0){
return true;
}else
return true;
}
//是否为满
public boolean isFull(){
if(top==SIZE){
return true;
}else
return false;
}
//出栈
public int pop(){
int temp;
if(top==0){
return 0;
}else{
top--;
temp=stack[top];
return temp;
}
}
public static void main(String[] args) {
SeqStack stack=new SeqStack();
stack.push(2);
stack.push(3);
stack.push(7);
stack.push(5);
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());
}
}
* 顺序结构栈
*
*/
public class SeqStack {
private final int SIZE=10;
private int[] stack=new int[SIZE];
private int top=0;
//入栈
public boolean push(int elem){
if(top==SIZE){
return false;
}else{
stack[top]=elem;
top++;
return true;
}
}
//是否为空
public boolean isEmpty(){
if(top==0){
return true;
}else
return true;
}
//是否为满
public boolean isFull(){
if(top==SIZE){
return true;
}else
return false;
}
//出栈
public int pop(){
int temp;
if(top==0){
return 0;
}else{
top--;
temp=stack[top];
return temp;
}
}
public static void main(String[] args) {
SeqStack stack=new SeqStack();
stack.push(2);
stack.push(3);
stack.push(7);
stack.push(5);
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());
System.out.println(stack.pop());
}
}