标签:
1 public class Stack { 2 private int maxSize=2;//栈容量,初始为2,(用于表达式求值,操作数栈) 3 private int top=-1;//栈顶指针 4 private int[] data=new int[maxSize];//数据 5 //判空 6 public boolean IsEmpty(){ 7 if(top==-1) 8 return true; 9 else 10 return false; 11 } 12 //判满 13 public boolean IsFull(){ 14 if(top==maxSize-1) 15 return true; 16 else 17 return false; 18 } 19 //圧栈 20 public boolean Push(int elem){ 21 if(IsFull()) 22 return false; 23 else{ 24 data[++top]=elem; 25 return true; 26 } 27 } 28 //出栈 29 public int Pop(){ 30 if(IsEmpty()){ 31 return -65535; 32 } 33 else{ 34 return data[top--]; 35 } 36 } 37 }
总结:
标签:
原文地址:http://www.cnblogs.com/jinfengxie/p/5167350.html