#include
#include
using namespace std ;
#define MAX_SIZE 10
template < class T >
class SeqStack
{
public :
SeqStack ()
: _top(- 1 )
, _capacity ( MAX_SIZE)
{
_stack = new T [_capacity ];
if ( NULL == _stack)
{
exit (-1 );
}
}
~SeqStack ()
{
delete []_stack ;
}
public :
T Pop ()
{
//栈空结束程序
if ( Empty ())
{
exit (-1 );
}
//若栈不空返回栈顶元素
return _stack [ _top--];
}
void Push ( const T & elem )
{
//栈满结束程序
if ( Full ())
{
exit (-1 );
}
_stack [++_top ] = elem;
}
T GetTop ()
{
//若栈不空返回栈顶元素
if ( Empty ())
{
exit (-1 );
}
return _stack [ _top];
}
bool Empty () const
{
return _top == - 1;
}
bool Full () const
{
return _top == _capacity - 1;
}
private :
int _top ; //栈顶指示
T * _stack ; //顺序栈
int _capacity ; //栈可容纳元素
};
bool IsLegal( char * sourse , char * dest )
{
SeqStack ss ;
if ( strlen (sourse ) != strlen( dest ))
{
return false ;
}
ss .Push (* sourse++); //第一个元素入栈
while (* dest != '