#include <iostream>
using namespace std;
int trueforever=0;//初始化为永真
int falseforever=0;//初始化为永假
struct BTnode
{
int data;
BTnode *Lchild;
BTnode *Rchild;
};
template <class ElemType>
class SqStack
{
public:
SqStack(int m);
~SqStack()
{
delete[]Base;
}
bool StackEmpty()
{
return(Base==Top);
}
bool GetTop(ElemType &e);
bool Push(const ElemType &e);
bool Pop(ElemType &e);
private:
int StackSize;
ElemType *Base;
ElemType *Top;
};
template <class ElemType>
SqStack<ElemType>::SqStack(int m)
{
Top=Base=new ElemType[m];
StackSize=m;
}
template <class ElemType>
bool SqStack<ElemType>::GetTop(ElemType &e)
{
if(Top==Base)
return false;
e=*(Top-1);
return true;
}
template<class ElemType>
bool SqStack<ElemType>::Push(const ElemType &e)
{
ElemType *newbase;
if(Top-Base>=StackSize)
{
newbase=new ElemType[StackSize+10];
if(!newbase)
return false;
for(int i=0;i<StackSize;i++)
newbase[i]=Base[i];
delete[]Base;
Base=newbase;
Top=Base+StackSize;
}
*Top++=e;
return true;
}
template <class ElemType>
bool SqStack<ElemType>::Pop(ElemType &e)
{
if(Top==Base)
return false;
e=*--Top;
return true;
}
class BinaryExpTree
{
public:
BinaryExpTree ();
~BinaryExpTree ();
bool Create(char ch[],int *a);
int Evaluate();
void check(char ch[],int count,int *a);
private:
BTnode *m_T;
void _DestroyBT(BTnode* &);
int _Evaluate(BTnode* &);
bool _JudgeSimbol(const char &);
char _Precede(const char &t1,const char &t2);
int _Opreate(const int &,const char &,const int &a
C++重言式判别
最新推荐文章于 2024-05-02 18:49:34 发布