# Include <iostream>
Using namespace STD;
Const int maxstacksize = 20;
Template <class T>
Class seqstack
{
Public:
Seqstack (t a [], int n =-1): Top (N)
{
If (n> maxstacksize | n <0)
Cout <"N value error !! "<Endl;
Int I;
For (I = 0; I <n; I ++)
Data [I] = A [I];
}
~ Seqstack ()
{
Top =-1;
Cout <"the sequence Stack has been analyzed !! "<Endl;
}
Bool isempty ()
{
Return (Top =-1 );
}
Bool isfull ()
{
Return (Top = (MaxStackSize-1 ));
}
Void push (t x)
{
If (isfull ())
{
Cout <"the stack is full, and the stack import operation cannot be completed !! "<Endl;
Exit (1 );
}
Data [Top] = X;
Top ++;
}
Void POP (T & X)
{
If (isempty ())
{
Cout <"the stack is empty, and the operation on the outbound stack cannot be completed !! "<Endl;
Exit (1 );
}
X = data [Top];
-- Top;
}
T gettop ()
{
Return data [Top-1];
}
Void showstack ()
{
Int I;
For (I = 0; I <top; I ++)
Cout <data [I] <",";
Cout <Endl;
}
PRIVATE:
T data [maxstacksize];
Int top;
};
Int main ()
{
Int A [10] = {1, 2, 4, 5, 6, 7, 8, 9, 10 };
Seqstack <int> seq (A, 10 );
Seq. showstack ();
Int x = 11;
Seq. Push (X );
Cout <"11:" <Endl;
Seq. showstack ();
Seq. Pop (X );
Cout <"the result after the stack is output is:" <Endl;
Seq. showstack ();
Int y = seq. gettop ();
// Seq. showstack ();
Cout <"the top element of the stack is:" <Y <Endl;
Return 0;
}