資源簡介
利用棧根據邏輯運算符的優先順序從底往上建立二叉樹,遞歸賦值,采用二叉樹的后序遍歷求邏輯表達式的值
代碼片段和文件信息
#include?
using?namespace?std;
int?trueforever=0;//初始化為永真
int?falseforever=0;//初始化為永假
struct??BTnode?
{
????????int?data;
????????BTnode?*Lchild;
????????BTnode?*Rchild;
};
????
template?
class?SqStack
????{
????public:
????????SqStack(int?m);
????????~SqStack()
{?
????????????delete[]base;
????????}
????????bool?StackEmpty()
{
???????????return(base==Top);?
????????}
????????void?ClearStack()
{
????????????Top=base;
????????}
????????bool?GetTop(ElemType?&e);
????????bool?Push(const?ElemType?&e);
????????bool?Pop(ElemType?&e);
????private:??
????????int?StackSize;
????????ElemType?*base;
????????ElemType?*Top;
};
??
template?
SqStack::SqStack(int?m)
{
????Top=base=new?ElemType[m];
????Stac
- 上一篇:C語言課程設計報告大一入學
- 下一篇:c++課設 公司工資管理
評論
共有 條評論