📄 caluhelp.h
字号:
//======== Copyright(C) ?????????????? All rights reserved! ======
// Copyright contents herein, currently it is not defined!!
//
// Purpose: Currently no Template supporting!!!
//
// $Date: $
// $Nokeywords: $
//----------------------------------------------------------------
// Log:
//----------------------------------------------------------------
// Programmer: wuwenxi
//================================================================
#ifndef __CALUHELP_CPP__
#define __CALUHELP_CPP__
#define ALLOC_ONCE 16
// Fixme: The flow macros should become the enum in the class!!!
#define NUMBER_TYPE 0
#define OPERATOR_TYPE 1
#define OP_ADD '+'
#define OP_SUB '-'
#define OP_MUL '*'
#define OP_DIV '/'
#define OP_LEFT_PAR '('
#define OP_RIGHT_PAR ')'
#define DOT '.'
#define NEGATIVE '_' // instread _ of - to present the negative number
class Element
{
public:
float value;
int type;
};
class CCaluHelp
{
public:
// Inner class description queue and stack struct
class HelpQueue
{
public:
// Constructr, malloc a certain memory, it can be
// increment later if the memory is not enough
HelpQueue( );
// Destructor
~HelpQueue( );
public:
Element& Front( void );
void AddToTail( const Element& elem );
bool Empty( void ) const;
int UsedLength( void ) const;
int FreeLength( void ) const;
private:
Element * m_pMem;
int m_nAllocCount;
Element * m_pStart;
Element * m_pEnd;
Element * m_pFree;
private:
bool EnsureCapacity( void );
private:
// Nerver allowed the flow operations
// in the purpose of the simplely to do
// Actually, the flow control is not needed
HelpQueue( const HelpQueue& );
HelpQueue& operator=( const HelpQueue& );
};
struct HelpStackNode
{
Element value;
HelpStackNode * next;
};
class HelpStack
{
public:
// Constructor, Destructor
HelpStack( );
~HelpStack( );
public:
void Push( const Element & elem );
Element Pop( void ); // delete the node
void PopMatch( const Element & elem, HelpStack& stack );
bool Empty( void ) const;
void ClearStack( void );
private:
HelpStackNode * m_Top;
private:
void Clear( void );
};
//
// Operations
//
float CaluExpr( const char * pcszExpr );
private:
// Gen Postfix expr ( 将pszExpr代表的中缀表达式转换为后缀表达式 )
void ParseExpr( const char * pcszExpr, HelpQueue& queue );
// 根据后缀表达式计算最后结果
float CaluPostfix( HelpQueue& postfixQueue );
};
#endif // __CALUHELP_CPP__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -