/**
* @ Author yuanzhenhui
* @ Serialdata 2006-9-10
* @ Version 1.0
*
*/
Stack Interface
Public interface stackinterface {
Public Boolean isempty ();
Public Boolean isfull ();
Public void push (Object OO) throws overflowexception;
Public object POP () throws underflowexception;
Public object get ();
}
// Custom exception
Class overflowexception extends exception {
Public overflowexception (){
System. Out. println ("this is an exception ");
}
}
Class underflowexception extends exception {
Public underflowexception (){
}
}
Public class mystack implements stackinterface {
Private object table [];
// Top is the top element of the stack.
Private int Top =-1;
// Construct the stack of N storage units
Public mystack (int n ){
Table = new object [N];
}
Public Boolean isempty (){
Return Top =-1;
}
Public Boolean isfull (){
Return top> = table. Length-1;
}
Public void push (Object OO) throws overflowexception {
If (! This. isfull ()){
Top ++;
Table [Top] = Oo;
} Else {
Throw new overflowexception ();
}
}
Public object POP () throws underflowexception {
Object temp = NULL;
If (! This. isempty ()){
Temp = table [Top];
Table [Top] = NULL;
Top --;
} Else {
Throw new underflowexception ();
}
Return temp;
}
Public object get (){
If (! This. isempty ()){
Return table [Top];
} Else
Return NULL;
}
}