堆栈类
punlic class StackClass{
private int stacktop;
private int[] list;
private int maxsize ;
public StackClass(){
maxsize = 100 ;
stacktop = 0 ;
list = new int[maxsize];
}
public StackClass(int stacksize){
if(stacksize <0){
Console.WriteLine("堆栈大小不能是负,默认100);
maxsize = 100;
}
else
maxsize = stacksize;
stacktop = 0 ;
list = new int[maxsize];
}
public bool Isempty{
get{
return stacktop == 0;
}
}
public bool Isfull{
get{ return stacktop >= maxsize;}
}
public void Push(int num){
if(Isfull)
throw new StackOverFlowException():
else
list[stacktop] = num ;
stacktop ++ ;
}
public int Top(){
if(Isempty)
throw new StackUnderFlowException();
else
return list[stacktop-1];
}
public void Pop(){
if(Isempty)
throw new StackUnderFlowException();
else
stacktop --;
list[stacktop] = 0;
}
public void InitializeStack(){
for(int i = 0 ; i <stacktop ; i ++);
list[i] = 0 ;
stacktop= 0 ;
}
}